当前位置: 代码迷 >> Sql Server >> sql 多字段重复的查询、剔除
  详细解决方案

sql 多字段重复的查询、剔除

热度:41   发布时间:2016-04-24 20:13:05.0
sql 多字段重复的查询、删除
RT 例一张表如下
A    B
a1   b1
a1   b1
a1   b2
如何查询出重复记录a1 b1
如何删除其中一条重复记录 
分都悬赏了!
sql 多字段 数据

------解决方案--------------------
查询的语句

select * from t 
where (A,B) in (select A,B from t group by A,B having count(*) > 1)


加一列自增长列 id 后删除的语句如下


select * from t 
where (A,B) in (select A,B from t group by A,B having count(*) > 1)
and id not in (select min(id) from t group by A,B having count(*) > 1)
  相关解决方案