How to delete duplicate rows from a MySQL table

前端 未结 8 1764
悲哀的现实
悲哀的现实 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:21

    You can run an alter query and achieve this:

    ALTER IGNORE TABLE tbl_1
    ADD UNIQUE INDEX unq_idx(col1, col2, col3);
    

    I cant guarantee it will retain the first record among the duplicates, but MySQL usually does that.

提交回复
热议问题