美文网首页
23 sql 查找表中多余的重复记录

23 sql 查找表中多余的重复记录

作者: 天天向上的小M | 来源:发表于2017-08-03 16:06 被阅读9次

    查找表中多余的重复记录,重复记录是根据单个字段(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)

    相关文章

      网友评论

          本文标题:23 sql 查找表中多余的重复记录

          本文链接:https://www.haomeiwen.com/subject/nypplxtx.html