首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

重复记录怎么过滤

2012-01-31 
重复记录如何过滤啊IDProductIDCatName122a223a322a我想找出ProductID不重复的记录(重复的记录中,选择任意

重复记录如何过滤啊
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

热点排行