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


Please Help Members By Posting Answers For Below Questions

How is table type constraint applied to a table?

551


tell me what are the steps you will take to improve performance of a poor performing query? : Sql server database administration

567


How can you start sql server in different modes?

503


Explain what are the restrictions while creating batches in sql server?

587


What is sleeping status in sql server?

518






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?

481


How to replace null values in expressions using isnull()?

647


How optimize sql query with multiple joins in sql server?

413


How to update multiple rows with one update statement in ms sql server?

634


Do you know what are acid properties of transaction?

523


How do you create a clustered index?

528


How to set the current database in ms sql server?

524


What is the meaning of sql server?

528


What is difference between global temporary tables and local temporary tables?

658


what is a join? : Sql server database administration

542