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

What is meant by indexing?

499


What is the status of services on passive node for failover cluster in sql server? : sql server database administration

626


Explain insert into select statement?

515


What action plan is preferred if sql server is not responding?

527


What language is sql server written in?

523






What is Federation Root Database?

90


What options are available to audit login activity? : sql server security

629


What is the difference between row_number and dense_rank?

436


What are the options which must be set to allow the usage of optimistic models?

505


Explain activity monitors

612


What programming language would you use to create embedded functions in ssrs?

122


Can the query output be sorted by multiple columns in ms sql server?

548


Where are stored procedures in sql server?

556


Why should one not prefix user stored procedures with ‘sp_’?

585


How to convert character strings into numeric values?

567