How to delete duplicate rows from a MySQL table

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

    I'd do it following way, in MSSQL, but I think it should work with slight modifications in MySQL. Not executable, but should show the way.

    CREATE TEMPORARY TABLE #Table (Col1, Col2, Col3);
    INSERT INTO #Table (Col1, Col2, Col3) SELECT DISTINCT Col1, Col2, Col3 FROM Table;
    DELETE FROM Table;
    INSERT INTO Table (Col1, Col2, Col3) SELECT Col1, Col2, Col3 FROM #Table;
    DROP TABLE #Table;
    

提交回复
热议问题