SQL SERVER常用取重复记录的SQL语句
- 获取某字段或几个字段有重复的数据,可限定重复几条
select field1,field2 from table group by field1,field2 having count(field1)>1 - 获取某字段不重复的最新记录
select top * from table a where id in(select max(id) from table b group by field) order by id desc - 获取某字段的重复数
select count(field) from table group by field having count(field)>1 - 获取不重复的记录
select field1,field2 from table group by field1,field2 - 删除重复记录
delete from from table a where id not in(select max(id) from table b group by field)