查找表中多余的重复记录,重复记录是根据单个字段(DocId)来判断
select * from TableName
where DocId in (select DocId from TableName group by DocId having count(DocId) > 1)
例二:
select * from TableName
where UserName in (select UserName from TableName group by TableName having count(TableName) > 1 )
可以查出表中UserName相同的记录
2、删除表中多余的重复记录,重复记录是根据单个字段(DocId)来判断,只留有DocId最小的记录
delete from TableName
where DocId in (select DocId from TableName group by DocId having count(DocId) > 1)
and DocId not in (select min(DocId) from TableName group by DocId having count(DocId)>1)
网友评论