How to delete duplicate rows from a MySQL table

前端 未结 8 1765
悲哀的现实
悲哀的现实 2020-11-30 12:07

I have a MySQL table like:

ID, Col1, Col2, Col3, Col4, etc...

ID is a primary key and has been w

8条回答
  •  一个人的身影
    2020-11-30 12:20

    you can delete all the rows except one by using some function like Min(depends on db). Ex:

    delete from Table_Name
    where Id not in
    ( select min(Id)
    from  Table_Name
    group by ID, Col1, Col2, Col3, Col4);
    

提交回复
热议问题