SQL Server 2008: delete duplicate rows

后端 未结 6 897
北荒
北荒 2020-12-13 11:29

I have duplicate rows in my table, how can I delete them based on a single column\'s value?

Eg

uniqueid, col2, col3 ...
1, john, simpson
2, sally, ro         


        
6条回答
  •  抹茶落季
    2020-12-13 12:09

    You have many ways for deleting the duplicate records some of them are below...........

    Different ways to delete Duplicate records

    Using Row_Number() function and CTE

      with CTE(DuplicateCount) as  ( SELECT  ROW_NUMBER() OVER
    (PARTITION by UniqueId order by UniqueId ) as DuplicateCount from
    Table1 ) Delete from CTE where DuplicateCount > 1
    
      .Without using CTE*
    
    Delete DuplicateCount from ( Select Row_Number() over(Partition by
    UniqueId order by UniqueId) as Dup from Table1 ) DuplicateCount 
    where DuplicateCount.Dup > 1
    
     .Without using row_Number() and CTE
    
    Delete from Subject where RowId not in(select Min(RowId ) from
    Subject group by UniqueId)
    

提交回复
热议问题