Showing posts with label CTE. Show all posts
Showing posts with label CTE. Show all posts

Monday, April 29, 2019

Remove duplicates from SQL Table

Alot of time duplicates needed to be deleted. 

Case scenario,  When one reocrd is touched it can have same data with only different dates and may end up with duplicates when joining with Id

I normally use the below script to clean it off.

with cte as (
 select
Id ,row_number()over(partition by Id order by Id ) rn
from dbo.Table
)

DELETE from cte where rn>1

Popular Posts