How to delete duplicate rows based on multiple column from a table

Posted by Kirthiga under Sql Server category on | Points: 40 | Views : 1324
create table Test(Nos int,Data varchar)
insert into Test values(1,'A'),(2,'B'),(2,'C'),(3,'D'),(4,'D'),(4,'D'),(5,'E')
select * from Test

--Query to delete duplicate records
;with dup as
select *,ROW_NUMBER()over(partition by Nos,Data order by Nos,Data)DupNo from Test
)delete from dup where DupNo>1

select * from Test

Comments or Responses

Login to post response