Duplicate rows are the kind of bug that never announces itself. No error, no crash — just the same customer twice in a report, the same email getting a newsletter twice, and an import that fails one day because a value that was supposed to be unique suddenly is not. I ran into this on a real project, and the fix started with one short query.
The one query that finds them
If email is the column that should be unique, this is the check:
SELECT email , COUNT (*) AS occurrences FROM customers GROUP BY email HAVING COUNT(*) > 1 ;
Enter fullscreen mode
Exit fullscreen mode
HAVING does the filtering here, not WHERE — WHERE runs before grouping and cannot see COUNT(*) . The result is a short list of every duplicated value and how many times it appears. That list alone tells you how bad the problem is.
Two details people usually miss. First, NULL values all land in one group, so ten rows with a missing email look like ten duplicates — add WHERE email IS NOT NULL unless a missing value genuinely counts.…