MySQL – Remove Duplicate Entries with Unique ID

duplicationMySQLmysql-5.5

I have a CDR Table with a "unique id" column which is not a Primary Key. During an upgrade, there were a few days where instead of one entry for a caller ringing a queue, there was multiple entries for this caller. All the entries have the same unique ID.

What I would like to do, is delete all entries with the same unique ID, but leaving one entry. Is there a simple way to do this? All my searching turned up results on either, DB's with no unique ID, or with a Primary key. I have both a unique ID and No Primary key lol.

Thanks for your guidance!

PS: MySQL 5.5

Eg:
enter image description here

Best Answer

If more than, say, half the table needs to be removed, it is faster (etc) to

CREATE TABLE new LIKE real;
ADD PRIMARY KEY (...);   -- or UNIQUE
INSERT INTO new
    SELECT DISTINCT ... FROM real;
RENAME TABLE real TO old,
             new TO real;
DROP TABLE old;