首页 > 解决方案 > 从 SQLITE 中的两列中选择不同的值

问题描述

我有两列

tab1
col1   col2
a       1
a       2
b       3
b       6
c       4
d       5

我需要同时从两列中获取不同的值,例如:

result
col1     col2
a         1
b         3
c         4
d         5
select distinct col1, col2 from tab1 #is not giving such results.

这在sqlite中可能吗?

标签: sqlitegroup-bydistinctmin

解决方案


从您发布的示例数据中,我看到最简单的方法是group by col1获取最小值col2

select col1, min(col2)
from tab1
group by col1

推荐阅读