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 difference between indexing and hashing?

1179


What is purpose of normalization?

955


Is it important for a database administrator to understand the operating system and file access?

1006


Define clusters?

1093


What is nonclustered index with included columns ?

973


role of sql sever 2005 in database rather than any other database

1951


How to convert numeric expression data types by assignment operations?

1094


How can you start sql server in different modes?

980


Is BCNF better than 2NF & 3NF? Why?

1057


Can you tell me some of the common replication dmv's and their use? : sql server replication

934


Explain sql server service broker?

984


How can I track the changes or identify the latest insert-update-delete from a table?

975


What is the syntax to execute the sys.dm_db_missing_index_details? : sql server database administration

1163


How to add more data to the testing table in ms sql server?

1100


Explain in details security in SQL azure?

121