Search code examples
mysqldatabasemyisam

Mysql remove duplicate entries from table


I am having a table with the following columns

code  (varchar)
desc  (varchar)
attr1 (varchar)
attr2 (varchar)
attr3 (varchar)
reference

And the table contains bulk data.What i need is that i need to remove all entries from the table having duplicate values for code,attr1,attr2,attr3.I tried with adding unique index using these columns but didn't worked.Can i use some script for these.All these columns allows null values.my database engine is myisam.


Solution

  • You can add a unique index and drop the duplicates with

    ALTER IGNORE TABLE your_table
    ADD UNIQUE INDEX dup_idx (code, attr1, attr2, attr3);