How to delete duplicate rows in SQL Server?

后端 未结 23 1408
长情又很酷
长情又很酷 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:53

    DELETE FROM TBL1  WHERE ID  IN
    (SELECT ID FROM TBL1  a WHERE ID!=
    (select MAX(ID) from TBL1  where DUPVAL=a.DUPVAL 
    group by DUPVAL
    having count(DUPVAL)>1))
    

提交回复
热议问题