Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / brajesh

DECLARE temp CURSOR FOR SELECT id FROM cars1 c GROUP BY
c.id,c.name,c.year
DECLARE @id int
OPEN temp
FETCH next FROM temp
INTO @id

WHILE @@FETCH_STATUS=0
BEGIN
IF EXISTS (SELECT id FROM cars1 GROUP BY cars1.id
HAVING count(*)>1 AND id=@id)
DELETE TOP(SELECT count(*)-1 FROM cars1 WHERE
cars1.id=@id )FROM cars1 WHERE id=@id

FETCH next FROM temp
INTO @id
END

CLOSE temp
DEALLOCATE temp

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you know what are acid properties of transaction?

923


Do you know the cursor types?

1124


Does sql server 2016 have ssms?

921


What do you mean by authentication modes in sql server?

1045


Does windows server 2016 come with sql server?

887


How sql server enhances scalability of the database system?

1137


What is the difference between the 2 operating modes of database mirroring?

1069


what is dbcc? : Sql server database administration

978


How can you list all the columns in a database?

891


You want to use a perspective in an mdx query. How do you select the perspective?

235


Name some of the open source software that you can use in alternative to SSR?

155


What do you mean by an execution plan? Why is it used? How would you view it?

885


What is entity data services?

1012


How to create prepared statements using odbc_prepare()?

1003


How to perform backup for certificates in sql server? : sql server security

1040