Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Deleting duplicate records

$
0
0
Dears,

There are many ways to eliminate the duplicate records but using the CTE concept is amazing!!!

-- MSSQL 2005 and onwards

;WITH EliminateDup(Name,id,SAL,ROWID) AS
(
SELECT name,ID ,SAL,ROW_NUMBER()OVER(PARTITION BY name,ID,SAL ORDER BY ID)AS ROWID
FROM DUP1
)
--SELECT * FROM EliminateDup WHERE ROWID>1 -- to find out the duplicates
DELETE EliminateDup WHERE ROWID>1 -- to delete the duplicate records


-- akhilesh narayanan

Viewing all articles
Browse latest Browse all 13329

Trending Articles