Is it possible to delete duplicate rows in a table without
using a temporary table ?

Answer Posted / balaji

yes its very much possible.
create table #student
(name varchar(10),age integer)

insert into #student values ('A',12)
go 2
insert into #student values ('B',13)
go 3
insert into #student values ('C',15)
go 4
insert into #student values ('D',14)
go 5


SET ROWCOUNT 1
DELETE #student FROM #student A WHERE (SELECT COUNT(*) FROM
#student B WHERE A.NAME = B.NAME AND A.AGE = B.AGE) > 1
WHILE @@ROWCOUNT > 0
DELETE #student FROM #student A WHERE (SELECT COUNT(*) FROM
#student B WHERE A.NAME = B.NAME AND A.AGE = B.AGE) > 1
SET ROWCOUNT 0

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between report and query parameter. Why do we need different type of parameter?

559


What is a schema in ms sql server 2005?

558


Where is localdb stored?

547


What new data source types were added in ssrs 2014?

105


Do you know what are the restrictions that views have to follow?

614






Explain how to use linked server?

551


How to create a testing table with test data in ms sql server?

544


What is difference in performance between insert top (n) into table and using top with insert?

524


what is the system function to get the current user's user id? : Sql server database administration

546


Explain having clause?

521


How to define and use table alias names in ms sql server?

551


What is inner join in sql server joins?

530


What is the difference between set and select?

563


What is the difference between primary key and unique constraints?

500


Does union all remove duplicates?

603