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 are joins in sql and what are the different types of joins?

1014


Why are sql functions used?

1124


Can group functions be used in the order by clause in ms sql server?

1013


How to create a stored procedure with a statement block in ms sql server?

1070


What is the difference between a "where" clause and a "having" clause?

1160


What is the maximum size of sql server database?

1011


What is data modification?

977


if you encounter this kind of an error message, what you need to look into to solve this problem? : Sql server database administration

985


Tell me about builtinadministrator?

1001


List layers of abstraction microsoft architectured to provide relational db through cloud platform ?

183


What is 'Join' and explain its various types.

1138


What keyword you will use to get schema appended to the result set of a ‘for xml’ query?

1022


What is reference section?

1005


What do we need queues in sql service broker?

1065


Can we store videos inside the sql server table?

981