Finding duplicate values in a SQL table

后端 未结 30 4039
南旧
南旧 2020-11-21 13:18

It\'s easy to find duplicates with one field:

SELECT name, COUNT(email) 
FROM users
GROUP BY email
HAVING COUNT(email) > 1

So if we have

30条回答
  •  遇见更好的自我
    2020-11-21 13:41

    This should also work, maybe give it try.

      Select * from Users a
                where EXISTS (Select * from Users b 
                    where (     a.name = b.name 
                            OR  a.email = b.email)
                         and a.ID != b.id)
    

    Especially good in your case If you search for duplicates who have some kind of prefix or general change like e.g. new domain in mail. then you can use replace() at these columns

提交回复
热议问题