how to delete duplicate rows from a table in mysql

后端 未结 1 1876
傲寒
傲寒 2020-11-28 16:03

I need to delete duplicate record from table in mysql. So i have a table name \"employee\" fields are empid, empname, empssn

for getting duplicate record i have writ

相关标签:
1条回答
  • 2020-11-28 16:43

    Does the trick of wrapping it into a derived table work for this case? (Based on http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/)

    DELETE FROM employee WHERE (empid, empssn) NOT IN 
    (
    SELECT  empid, empssn FROM
    (
    SELECT MIN(empid) AS empid, empssn FROM employee GROUP BY empssn
    ) X
    );
    

    Edit Yep it seems to work this end.

    0 讨论(0)
提交回复
热议问题