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

Tell me what are the advantages of using stored procedures?

559


Explain query editor regions

604


Explain contrast amongst grouped and non-bunched records?

503


What is a covered index?

509


What is transact-sql ddl trigger?

622






what's the maximum size of a row? : Sql server database administration

532


Explain what is use of dbcc commands?

500


What are the benefits of normalization?

565


what is package and it uses and how can u call a package

1547


What is sql injection? How to protect against sql injection attack?

545


What are data regions?

90


how many type of indexing in database?

567


Explain about SQLOS?

575


Are all views updatable ?

716


What is data source document?

535