MySQL has a very obnoxious restriction that cannot use the table that is being updated/deleted/inserted in a sub-select.
But you can work around this by joining the table to be deleted (instead of using a sub-select).
Assuming you have some kind of unique identifier in your table (I assume a column id
in the following statement):
DELETE d
FROM table_with_duplicates d
JOIN (
SELECT min(id) as min_id, field
FROM table_with_duplicates
GROUP BY field
) keep ON keep.field = d.field
AND keep.min_id <> d.id;
This will keep one row for each of the duplicates (the one with the lowes value in the id
column).
If you want to delete all duplicate rows (not keeping at least one), simply remove the AND keep.min_id <> d.id
condition.
Edit
If you don't have a unique column, but want to remove all duplicates (not keeping at least one row), then you can use:
DELETE d
FROM table_with_duplicates d
JOIN (
SELECT field
FROM table_with_duplicates
GROUP BY field
HAVING count(*) > 1
) del ON del.field = d.field;