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 to write a query with a right outer join in ms sql server?

657


Can a table be moved to different filegroup?

727


What is user-defined scalar function?

722


What are “lost updates”?

775


List out what other servers you can use with ssrs?

115






What are diverse clauses that form a part of sql?

794


last function used in MS Access to convert sql what function will use in sql

1821


How to create an identity column?

850


What is a trigger and its types?

732


How do I debug a stored procedure in sql server?

726


What does <> symbol mean?

705


Explain different types of locks in sql server.

775


How real and float literal values are rounded?

816


What is filtered index?

821


What are the purposes of floor and sign functions?

731