Archive for December, 2011

MySQL remove duplicates

Friday, December 9th, 2011

DELETE n1 FROM table n1, table n2 WHERE n1.id > 10000 AND n1.id < 11000 AND n1.id > n2.id AND n1.EMAIL = n2.EMAIL;

The above MySQL query will delete duplicate email addresses between the id’s 10000 and 11000. Breaking the query into blocks of 1000 id’s will reduce strain the MySQL server.

MySQL find duplicates

Friday, December 9th, 2011

select EMAIL, count(EMAIL) as cnt
from TABLE
group by EMAIL
having cnt > 1 ORDER BY `cnt` DESC

The above MySQL query will find and list the number of multiple duplicate emails in a table.