How to delete duplicate rows in SQL Server 2008?

前端 未结 4 1281
栀梦
栀梦 2021-01-06 18:26

How can I delete duplicate rows in SQL Server 2008?

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-06 19:09

    Assuming you have a primary key called id and other columns are col2 ...coln, and that by "duplicate" rows you mean all rows where all column values except the PK are duplicated

    delete from A where id not in
    (select min(id) from A
    group by col2, col3, ...coln) as x
    

    i.e. group on all non-PK columns

提交回复
热议问题