这样只选第一条的查询怎么写SQL语句?

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:34:00
字段 m n
1 a
1 b
2 c
2 d
1 e
2 f
我要查出 1 a
2 c
就是m 中所有重复值的第一条
求解

不会吧。 那么简单的问题 回答成什么样子了。
假设你的表名为A
select m,min(n) from A group by m

用distinct

select m,n from table where id in(select m,min(id) from table group by m)

不是很确定,最近ORALE 用的比较多~
ORACLE 有个ROWID 是不变的,SQL应该也有吧,不知道是不是ID,楼主可以自己查下!

select top 1 from (select distinct m,n from tablename) a

select top 1 from table

select distinct field from table

distinct +排序
不用 top,直接排序就可以出来了
example:
conn.execute="select distinct m from table order by n desc"