How to delete duplicates on a MySQL table?

后端 未结 25 2420
遇见更好的自我
遇见更好的自我 2020-11-22 01:35

I need to DELETE duplicated rows for specified sid on a MySQL table.

How can I do this with an SQL query?

         


        
25条回答
  •  忘了有多久
    2020-11-22 01:53

    This work for me to remove old records:

    delete from table where id in 
    (select min(e.id)
        from (select * from table) e 
        group by column1, column2
        having count(*) > 1
    ); 
    

    You can replace min(e.id) to max(e.id) to remove newest records.

提交回复
热议问题