重复记录如何过滤啊
ID ProductID CatName
1 22 a
2 23 a
3 22 a
我想找出 ProductID不重复的记录 (重复的记录中,选择任意一条出来就行)
------解决方案--------------------select * from tablename t where t.id in (select max(id) from tablename group by ProductID);
相同ProductID选择ID最大的一行。
------解决方案--------------------select * from a where ID in (select top 1 ID from a b where b.ProductID = a.ProductID )
------解决方案--------------------select * from tablename t where t.id in (select min(id) from tablename group by ProductID);
------解决方案--------------------ID ProductID CatName
1 22 a
2 23 a
3 22 a
我想找出 ProductID不重复的记录 (重复的记录中,选择任意一条出来就行)
select a.* from tb a,(select productid , min(id) id from tb group by productid) b where a.productid = b.productid and a.id = b.id