Finding Duplicates with SQL

Posted by

Quite a handy query for finding duplicates in a table (setting ’email’ to the field you’re checking for duplicates and ‘users’ to the table this field is in of course)

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

via Finding Duplicates with SQL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.