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
What is the purpose of object explorer and its features? : sql server management studio
Explain the use of keyword with encryption. Create a store procedure with encryption?
When a primary key constraint is included in a table, what other constraints does this imply?
What are the different types of replication are there in sql server 2000?
What do you mean by a dependent functionality in a build?
What is Lock table in SQL?
What are user defined functions in ms sql server?
What happens if null values are involved in boolean operations?
How to fetch the next row from a cursor with a "fetch" statement?
What is the command used to recompile the stored procedure at run time?
What are data resources?
Define full outer join?
What is the recovery model? List the types of recovery model available in sql server?
What happens if date-only values are provided as date and time literals?
How to edit table in sql server 2017?