Delete duplicates from table

Sometimes you end up with a lot of duplicates in a table and you need to get rid of them quickly.

Do this;

create table tmp like zipcodes;

alter table tmp add unique (zip, city, state);

insert into tmp select * from zipcodes
on duplicate key update;

rename table zipcodes to deleteme, tmp to zipcodes;

drop table deleteme;

This entry was posted in mysql. Bookmark the permalink.

Comments are closed.