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

What is the purpose of object explorer and its features? : sql server management studio

1199


Explain the use of keyword with encryption. Create a store procedure with encryption?

952


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

980


What are the different types of replication are there in sql server 2000?

1033


What do you mean by a dependent functionality in a build?

1134


What is Lock table in SQL?

1460


What are user defined functions in ms sql server?

989


What happens if null values are involved in boolean operations?

981


How to fetch the next row from a cursor with a "fetch" statement?

1066


What is the command used to recompile the stored procedure at run time?

1069


What are data resources?

904


Define full outer join?

945


What is the recovery model? List the types of recovery model available in sql server?

898


What happens if date-only values are provided as date and time literals?

1013


How to edit table in sql server 2017?

921