How to Find Duplicate Rows in MySQL
Last updated July 25, 2026 · By the SaturnSQL team
GROUP BY the columns that should be unique and keep groups with HAVING COUNT(*) > 1. Join that result back to the table when you need to see the full duplicated rows, not just the keys.
The columns in the GROUP BY define what counts as a duplicate, so this finds customers sharing an email regardless of what else differs. Watch out for NULLs: they group together here, but a UNIQUE constraint treats each NULL as distinct, so the two definitions disagree on nullable columns.
SELECT email, COUNT(*) AS dupes
FROM customers
GROUP BY email
HAVING COUNT(*) > 1;See the full rows
The subquery finds the duplicated keys and the join pulls back every full row that matches, which is what you need in order to decide which copy to keep. Ordering by the grouped column and then the id puts the copies next to each other for comparison.
SELECT c.*
FROM customers c
JOIN (
SELECT email FROM customers
GROUP BY email HAVING COUNT(*) > 1
) d ON d.email = c.email
ORDER BY c.email, c.id;Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free