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
Tell me what is fill factor?
What is the recovery model?
What are the types of ssrs?
What is table value parameters (tvp)?
What are entities and relationships?
What is a partition key?
What is reference section?
How to perform backup for certificates in sql server? : sql server security
Explain following error properties?
What are blobs, tables, and Queues? Is SQL is the standard way to query blobs, tables, and queues?
How to concatenate two binary strings together?
What is the difference between osql and query analyzer?
What are the different normalization forms?
What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?
What is a View ? Can we insert, Update and delete a view?