Monday 7 September 2015

Find and remove duplicate rows - WITH CTE

with CTE as (

select

 col1
      ,col2
      ,col3
      ,col4
      ,col5
      ,col6

  ,RN = ROW_NUMBER()OVER(PARTITION BY  col1 ,col2  ORDER BY col1,col2)

  FROM [database].[schema].[table]
)
--select * from cte where RN >1

delete from cte where RN >1

No comments:

Post a Comment

Your views:-