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
tell me what are the steps you will take to improve performance of a poor performing query? : Sql server database administration
What does asynchronous call backs means?
What are the requirements on sql server network connections?
How do I setup a sql server database?
What is a deadlock and what is a live lock?
What is an indexed view?
Does a full backup include transaction log?
What is updatable resultset?
You have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem?
what are isolation levels? : Sql server database administration
How will you monitor replication latency in transactional replication? : sql server replication
What is the stuff and how does it differ from the replace function?
What is de-normalization and what are some of the examples of it?
What is table join?
what is a sub-report?