Find and Delete Duplicate Values

Arul44ece
Posted by Arul44ece under Sql Server category on | Points: 40 | Views : 998
Duplicate Values:

We can find out Duplicate values using below queries.


SELECT Name , COUNT(*) TotalCount 
FROM sah
GROUP BY Name
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC

--find duplicate and delete
;with cte as (
select *,ROW_NUMBER()over(partition by name order by name)Rn from sah
)
select * from cte where Rn >1


-- Delete duplicate
;with cte as (
select *,ROW_NUMBER()over(partition by name order by name)Rn from sah
)
delete from cte where Rn >1

Comments or Responses

Login to post response