Wednesday, December 7, 2011

sql query

find duplicate record


select NAME, count(*)dups
from SHERA
group by NAME
having count(*) > 1
------------------------------

Delete duplicate record

with tt(Name,dups) --CTE
as
(
select NAME, ROW_NUMBER() over(partition by Name order by NAME) dups
from SHERA
)
delete from tt where dups>1


No comments:

Post a Comment