sql过滤重复数据

时间:2007-08-09 08:42   作者:    阅读:264

昨天碰到一个Case:
数据库表tbProduct里有数据库

idcompanyproduct
1chenrealibm pc
2realmems mouse
3real11111
4chenrealddddd
5chenrealcccc
6realmeqqqqq
7realmecccc
8real1112222
9chenreal88888

先要求列出最新的数据,但如果company重复的需要过滤掉
简单的DISTINCT无法实现的,这里需要用到 GROUP BY
我的解决方法:
select * from tbProduct where [id] in (select max([id]) from tbProduct group by company) order by [id] desc

 

评论
0/200