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 / sunil

set rowcount 1 -- set row count 1

delete a from Employee a
where (select count(*) from Employee e where e.empname =
a.empname) > 1

while @@rowcount > 0
begin
delete a from Employee a
where (select count(*) from Employee e where e.empname =
a.empname) > 1
end
set rowcount 0

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me what is fill factor?

560


What is the recovery model?

566


What are the types of ssrs?

108


What is table value parameters (tvp)?

549


What are entities and relationships?

562






What is a partition key?

523


What is reference section?

505


How to perform backup for certificates in sql server? : sql server security

600


Explain following error properties?

564


What are blobs, tables, and Queues? Is SQL is the standard way to query blobs, tables, and queues?

117


How to concatenate two binary strings together?

617


What is the difference between osql and query analyzer?

547


What are the different normalization forms?

622


What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?

600


What is a View ? Can we insert, Update and delete a view?

633