Here I have used CTE and ROW_NUMBER to delete duplicate records.
/* Delete Duplicate Records */
WITH CTE (Col1, DuplicateRowCount)
AS
(SELECT Col1, ROW_NUMBER() OVER(PARTITION BY Col1 ORDER BY Col1) AS DuplicateRowCountFROM DuplicateRcordTable)
DELETE FROM CTE WHERE DuplicateRowCount > 1 The above command will delete duplicate record in table i.e DuplicateRcordTable. which have duplicate record of column Col1 in table.
/* Delete Duplicate Records */
WITH CTE (Col1, DuplicateRowCount)
AS
(SELECT Col1, ROW_NUMBER() OVER(PARTITION BY Col1 ORDER BY Col1) AS DuplicateRowCountFROM DuplicateRcordTable)
DELETE FROM CTE WHERE DuplicateRowCount > 1 The above command will delete duplicate record in table i.e DuplicateRcordTable. which have duplicate record of column Col1 in table.
No comments:
Post a Comment