Wednesday, April 24, 2013

Delete duplicate records

create table xyz(id int,name varchar(500))
insert into xyz select '1','a'insert into xyz select '1','b'insert into xyz select '2','c'insert into xyz select '2','d'
with xyz1 as (select *,rn=ROW_NUMBER() over (partition by id order by id) from xyz)delete from xyz1 where rn>1

No comments:

Post a Comment