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 is awe?

0 Answers  


What is sql server profiler?

0 Answers  


What is a primary index?

0 Answers  


What is 1nf 2nf and 3nf?

0 Answers  


What are types of subqueries?

0 Answers  






How to create prepared statements using odbc_prepare()?

0 Answers  


What is amo? : sql server analysis services, ssas

0 Answers  


What is Schema? and why we use schemas?

4 Answers  


What is the process of indexing?

0 Answers  


Tell me what is normalization? Explain different forms of normalization?

0 Answers  


Define primary key?

0 Answers  


How do I start sql server 2016?

0 Answers  


Categories