Feb. 28, 2013, 3:09 p.m.
IT

MySQL remove duplicate rows

If you have a table as follows:

Field1Field2Field3
John2011-10-01G
John2011-10-01G
John2011-10-01G
George2011-01-02B
Klaus2001-01-01B

and you would like to remove all duplicate rows, the easiest method is to create an unique index like so:

alter ignore table TABLENAME add unique index INDEXNAME (Field1, Field2, Field3); 

then

alter table PCODES drop index xxx;

all the duplicate rows will be removed as follows:

Field1Field2Field3
John2011-10-01G
George2011-01-02B
Klaus2001-01-01B