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 can we solve concurrency problems?
How to provide values to stored procedure parameters in ms sql server?
Define clusters?
What are three ways you can use an identity value inside a trigger? Why would you prefer one way over another?
How to replace the Query Result 'Null Value' with a text ?
Do you know the policy based administration feature of sql server 2008?
Why does sql studio use a single registered database repository? : sql server management studio
Disadvantages of the indexes?
I have triggers,views,functions,stored Procedures for a table. When I am dropping that table which objects are deleted?
What is query optimization process?
Why transaction is important?
What is a field in a table?
Explain what are page splits? : SQL Server Architecture
what are the disadvantages of cursors? : Sql server database administration
How to receive output values from stored procedures?