How to delete duplicates on a MySQL table?

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

    Suppose you have a table employee, with the following columns:

    employee (first_name, last_name, start_date)
    

    In order to delete the rows with a duplicate first_name column:

    delete
    from employee using employee,
        employee e1
    where employee.id > e1.id
        and employee.first_name = e1.first_name  
    

提交回复
热议问题