WITH CTE([FirstName],
[LastName],
[Country],
DuplicateCount)
AS (SELECT [FirstName],
[LastName],
[Country],
ROW_NUMBER() OVER(PARTITION BY [FirstName],
[LastName],
[Country]
ORDER BY ID) AS DuplicateCount
FROM [SampleDB].[dbo].[Employee])
DELETE FROM CTE
WHERE DuplicateCount > 1;
It removes the rows having the value of [DuplicateCount] greater than 1
https://www.sqlshack.com/different-ways-to-sql-delete-duplicate-rows-from-a-sql-table/
[LastName],
[Country],
DuplicateCount)
AS (SELECT [FirstName],
[LastName],
[Country],
ROW_NUMBER() OVER(PARTITION BY [FirstName],
[LastName],
[Country]
ORDER BY ID) AS DuplicateCount
FROM [SampleDB].[dbo].[Employee])
DELETE FROM CTE
WHERE DuplicateCount > 1;
It removes the rows having the value of [DuplicateCount] greater than 1
https://www.sqlshack.com/different-ways-to-sql-delete-duplicate-rows-from-a-sql-table/
No comments:
Post a Comment