sql过滤重复数据

ChenReal

昨天碰到一个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