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 are joins in sql and what are the different types of joins?
Why are sql functions used?
Can group functions be used in the order by clause in ms sql server?
How to create a stored procedure with a statement block in ms sql server?
What is the difference between a "where" clause and a "having" clause?
What is the maximum size of sql server database?
What is data modification?
if you encounter this kind of an error message, what you need to look into to solve this problem? : Sql server database administration
Tell me about builtinadministrator?
List layers of abstraction microsoft architectured to provide relational db through cloud platform ?
What is 'Join' and explain its various types.
What keyword you will use to get schema appended to the result set of a ‘for xml’ query?
What is reference section?
What do we need queues in sql service broker?
Can we store videos inside the sql server table?