How to remove duplicate entries from a mysql db?

后端 未结 8 1351
南旧
南旧 2020-12-02 10:41

I have a table with some ids + titles. I want to make the title column unique, but it has over 600k records already, some of which are duplicates (sometimes several dozen ti

8条回答
  •  既然无缘
    2020-12-02 11:16

    Below query can be used to delete all the duplicate except the one row with lowest "id" field value

    DELETE t1 FROM table_name t1, table_name t2 WHERE t1.id > t2.id AND t1.name = t2.name
    

    In the similar way, we can keep the row with the highest value in 'id' as follows

     DELETE t1 FROM table_name t1, table_name t2 WHERE t1.id < t2.id AND t1.name = t2.name
    

提交回复
热议问题