How to delete duplicate rows in SQL Server?

后端 未结 23 1375
长情又很酷
长情又很酷 2020-11-22 00:58

How can I delete duplicate rows where no unique row id exists?

My table is

col1  col2 col3 col4 col5 col6 col7
john  1          


        
23条回答
  •  北海茫月
    2020-11-22 01:32

    Without using CTE and ROW_NUMBER() you can just delete the records just by using group by with MAX function here is and example

    DELETE
    FROM MyDuplicateTable
    WHERE ID NOT IN
    (
    SELECT MAX(ID)
    FROM MyDuplicateTable
    GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)
    

提交回复
热议问题