日期:2014-05-18  浏览次数:20370 次

请教sql查询怎么忽略重复行
做了个小bbs
要在bbs回帖表(bbs_post) 中查询10个最新的ThreadId(主帖表的外键)
select top 10 id,threadId,pubdate from bbs_post order by pubdate
查询结果如下:
id threadId pubdate
17 34 2008-12-15 
18 20 2008-12-15 
19 20 2008-12-15
。。。。。
。。。。
请教各位,怎么忽略或跳过重复的记录而找到最新的10条呢?
18 20  
19 20

------解决方案--------------------
id不要显示,可这样:
select distinct top 10 threadId,pubdate from bbs_post order by pubdate
------解决方案--------------------
用 distinct
------解决方案--------------------
探讨
id不要显示,可这样:
select distinct top 10 threadId,pubdate from bbs_post order by pubdate

------解决方案--------------------
distinct
------解决方案--------------------
select distinct top 10 threadId,pubdate from bbs_post order by pubdate 

这样查询出时间并不是最新的啊?

如果是用desc倒叙后,编号就不对了??
------解决方案--------------------
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
参考一下。
------解决方案--------------------
distinct关键字 去除重复
------解决方案--------------------
distinct!!!
关键你是怎样用!!
------解决方案--------------------
SQL code
select top 10 t.threadId,t.pubdate 
 from (select threadId,max(pubdate) as pubdate from bbs_post) t order by pubdate