How to delete the duplicate rows from a table in SQL Server ??

Answers were Sorted based on User's Feedback



How to delete the duplicate rows from a table in SQL Server ??..

Answer / vnreddy

create table sampletbl(id int,name varchar(100))

insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(2,'bb')
insert into sampletbl values(2,'bb')

with cte as(
select ROW_NUMBER() over (partition by id order by id) as r_no,* from sampletbl)
delete from cte where r_no>1

select * from sampletbl

Is This Answer Correct ?    10 Yes 2 No

How to delete the duplicate rows from a table in SQL Server ??..

Answer / sudha511

select distinct * into #temp from sampletbl
delete sampletbl
insert into sampletbl
select * from #temp
drop table #temp

Is This Answer Correct ?    2 Yes 0 No

How to delete the duplicate rows from a table in SQL Server ??..

Answer / himmat

delete from table name
having count(column name)>1
group by column name

Is This Answer Correct ?    15 Yes 25 No

Post New Answer

More SQL Server Interview Questions

What do we need queues in sql service broker?

0 Answers  


Can a function call a stored procedure in sql server?

0 Answers  


What are the different types of queries?

1 Answers  


How to use subqueries with the exists operators in ms sql server?

0 Answers  


Explain filtered indexes benefits?

0 Answers  






What are Magic Table?

34 Answers   3i Infotech, Digiweb, Evalueserve, NIIT, PL,


What are the difference between data length and length in SQL Server-2008?

3 Answers   Scio Healthcare,


When a primary key constraint is included in a table, what other constraints does this imply?

0 Answers  


How many joins in sql server?

0 Answers  


What command is used to rename the database?

0 Answers  


How do I schedule a sql server profiler trace?

0 Answers  


Can you index views?

0 Answers  


Categories