Monday 21 May 2012

Delete Duplicate Data - SQL

Delete Duplicate Data without Using primary key and Identity key:

Example:
Id
Name
1
Test
1
Test
1
Test

USE Test
Go
WITH Duplicates AS
(
    SELECT Name,Id,
      ROW_NUMBER() OVER (PARTITION BY Id,Name ORDER BY Id) AS 'RowNum'
    FROM dbo.TestDuplicates  
     
)delete FROM Duplicates WHERE RowNum>1
SELECT * FROM dbo.TestDuplicates

After using this:

Id            Name
1              Test

Post By : Urvish Patel
Blog By : Dipen Shah
Stay Tuned...We rocked...

1 comment:

  1. Informative article, just what I was looking for. Keep on posting these types of useful tips.
    Historical Options Prices

    ReplyDelete