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
Explain acid?
How to stop a loop early with break statements in ms sql server?
What are transactions in sql?
What are blobs, tables, and Queues? Is SQL is the standard way to query blobs, tables, and queues?
Explain the use of containers in ssis and also their types?
what are the critical issues you have resloved in your company
What is subquery in sql?
what are the steps you will take, if you are tasked with securing an sql server? : Sql server database administration
What is an index. What are the types?
What does ss stand for sexually?
what are different types of raid configurations? : Sql server database administration
How to get the definition of a user defined function back?
List some of the rules that apply to creating and using a ‘view’
Do you know what is user defined datatypes and when you should go for them?
What is dbcc updateusage?