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
Tell me what are the advantages of using stored procedures?
Explain query editor regions
Explain contrast amongst grouped and non-bunched records?
What is a covered index?
What is transact-sql ddl trigger?
what's the maximum size of a row? : Sql server database administration
Explain what is use of dbcc commands?
What are the benefits of normalization?
what is package and it uses and how can u call a package
What is sql injection? How to protect against sql injection attack?
What are data regions?
how many type of indexing in database?
Explain about SQLOS?
Are all views updatable ?
What is data source document?