How to Remove Duplicate Rows in MySQL

Last updated July 25, 2026 · By the SaturnSQL team

Self-join DELETE: remove every row that shares its key columns with a lower id, keeping the earliest row. Alternatively rebuild the table with INSERT IGNORE into a copy that has a unique key, then swap the tables.

Keep the lowest id

DELETE c2 FROM customers c1
JOIN customers c2
  ON c2.email = c1.email
 AND c2.id > c1.id;

Rebuild with INSERT IGNORE

CREATE TABLE customers_dedup LIKE customers;
ALTER TABLE customers_dedup ADD UNIQUE KEY uq_email (email);
INSERT IGNORE INTO customers_dedup SELECT * FROM customers;
RENAME TABLE customers TO customers_old, customers_dedup TO customers;

Either way, add a unique index afterwards so the duplicates cannot come back.

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

Related MySQL guides

© 2026 Panda Capital Oy Ab. All rights reserved.