How to delete duplicates on a MySQL table?

后端 未结 25 2394
遇见更好的自我
遇见更好的自我 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 02:05

    This works for large tables:

     CREATE Temporary table duplicates AS select max(id) as id, url from links group by url having count(*) > 1;
    
     DELETE l from links l inner join duplicates ld on ld.id = l.id WHERE ld.id IS NOT NULL;
    

    To delete oldest change max(id) to min(id)

提交回复
热议问题