Xaprb is a great resource for SQL tricks, especially MySQL tricks. Here's an explanation of some techniques to delete duplicate rows with a grouped self-join. I needed this in order to add a unique index to a table.
[select/delete] bad_rows.*
from test as bad_rows
inner join (
select day, MIN(id) as min_id
from test
group by day
having count(*) > 1
) as good_rows on good_rows.day = bad_rows.day
and good_rows.min_id <> bad_rows.id;

tagged with: 