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
How to use "if ... Else if ... Else ..." Statement structures in ms sql server?
how to control the amount of free space in your index pages? : Sql server database administration
Do you know what is difference between index seek vs. Index scan?
Do you know what are acid properties of transaction?
What is data modification?
What authentication modes does sql server support?
What are the purposes and advantages stored procedure?
How you can get a list of all the table constraints in a database?
Which command is used for user defined error messages?
Can you use order by when defining a view?
How do I run a trace in sql server?
What is the language structure to add a record to a table?
How do I create a trace in sql server?
Explain the difference between cross join and full outer join?
What are types of scd? : sql server analysis services, ssas