Finding duplicate values in a SQL table - ADVANCED
- by Alex
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 a table
ID NAME EMAIL
1 John asd@asd.com
2 Sam asd@asd.com
3 Tom asd@asd.com
4 Bob bob@asd.com
5 Tom asd@asd.com
This query will give us John, Sam, Tom, Tom because they all have the same e-mails.
But what I want, is to get duplicates with the same e-mails and names.
I want to get Tom, Tom.
I made a mistake, and allowed to insert duplicate name and e-mail values. Now I need to remove/change the duplicates. But I need to find them first.