How to delete duplicate records in sql server using common table expression (CTE).


Sql Query to delete duplicate records

;WITH TempEmp (sEmpId,duplicateRecCount)
AS
(
  SELECT sEmpId,ROW_NUMBER() OVER(PARTITION by sEmpId ORDER BY iUserId)
  AS duplicateRecCount
  FROM [tblEmpM]
)
DELETE FROM TempEmp
WHERE duplicateRecCount > 1

2 thoughts on “How to delete duplicate records in sql server using common table expression (CTE).

Comments are closed.