Make a new table OR add a unique key, self join, and delete all but the minimum key
New table:
So you could make a new table without dups. I imagine you thought of this already.
CREATE TABLE new_test (field1 INTEGER, field2 INTEGER);
INSERT INTO new_test(field1,field2) SELECT DISTINCT field1,field2 FROM test;
DROP TABLE test;
RENAME TABLE new_test test;
If you had a unique key, you could do a self join and identify the targets by having a unique key >
than the minimum. If you didn't have such a key, you could make one:
Make unique key:
ALTER TABLE t2 ADD COLUMN (pk INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY(pk));
Anyway, now you can do a self join and keep MIN(pk):
Self-join and delete dups:
mysql> DELETE dups.* FROM t2 AS dups
INNER JOIN (
SELECT field1,field2,MIN(pk) as MPK FROM t2
GROUP BY field1,field2 HAVING COUNT(*) > 1 ) AS keep
ON keep.field1=dups.field1
AND keep.field2=dups.field2
AND keep.MPK <> dups.pk;