Delete duplicate rows from a table without primary key by
using a single query
Table Employee
empname salary
A 200
B 300
A 200
C 400
D 500
D 500
Output should be
A 200
B 300
C 400
D 500
Answer Posted / shankaranarayanan v
while exists(select count(*) from employee group by empname having count(*)>1)
begin
delete top(1) from employee where empname in
(
select min(empname) as deletedname
from employee
group by empname
having count(*)>1
)
end
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
How is table type constraint applied to a table?
tell me what are the steps you will take to improve performance of a poor performing query? : Sql server database administration
How can you start sql server in different modes?
Explain what are the restrictions while creating batches in sql server?
What is sleeping status in sql server?
You have a table with close to 100 million records recently, a huge amount of this data was updated now, various queries against this table have slowed down considerably what is the quickest option to remedy the situation?
How to replace null values in expressions using isnull()?
How optimize sql query with multiple joins in sql server?
How to update multiple rows with one update statement in ms sql server?
Do you know what are acid properties of transaction?
How do you create a clustered index?
How to set the current database in ms sql server?
What is the meaning of sql server?
What is difference between global temporary tables and local temporary tables?
what is a join? : Sql server database administration