Skip to content

Instantly share code, notes, and snippets.

@thewinterwind
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewinterwind/862b235c3c0aad3532dc to your computer and use it in GitHub Desktop.
Save thewinterwind/862b235c3c0aad3532dc to your computer and use it in GitHub Desktop.
How to remove duplicate rows from a MySQL table
-- For example, a members table that has duplicate emails
-- Needs unique id field to work
create temporary table tmpTable (id int);
insert tmpTable
(id)
select id
from members m
where exists
(
select *
from members m2
where m2.email = m.email
and m2.id > m.id
);
delete
from members
where ID in (select id from tmpTable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment