mustcodemore.com

2.02.2006

SQL Find Duplicates Query

Needed this today. Finds all occurences of a specified field that occurs more than once (or whatever number you want to replace)

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


also this finds only lines that have a single record


SELECT email
FROM users
GROUP BY email
HAVING ( COUNT(email) = 1 )

0 Comments:

Post a Comment

<< Home