古井献礼406多少一瓶:sql2000分组查询

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/04 22:05:55
topic表中有两个字段如下:
id topics
1 3232
2 43343
1 rerer
3 fdfdf
1 fdfd
2 fdfd
我想按id号分组,并只取每组的第一条记录,应如何写SQL语句?谢谢!

select (select top 1 from topic b where a.id=b.id)top1 from topic a group by id

select(select *
from topic
where a.id=b.id)top1
from topic
where order by id