WITH [GetDuplicate] AS
(
SELECT RowNum = ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Id DESC),
Name
FROM Employee
)
DELETE FROM [GetDuplicate] WHERE RowNum > 1
By using these commnad of line we can delete duplicate records from a table
WITH [GetDuplicate] AS
(
SELECT RowNum = ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Id DESC),
Name
FROM Employee
)
DELETE FROM [GetDuplicate] WHERE RowNum > 1
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegisterMembers onlyeBook · SQL ServerBasics of SQL ServerDownload nowWrite a blog post and earn +250 SHARP when it is approved.
Write a blog
Join the conversation! Your thoughts help the community grow.