adspace
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 different types of backups avaialabe in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration
What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?
What is a view in sql?
What are the pros and cons of putting a scalar function in a queries select list or in the where clause?
Why and when do stored procedure recompile?
List out the different types of locks available in sql server?
When should you use an instead of trigger?
What are the different subsets of sql?
Why we use the openxml clause?
You have a stored procedure, which execute a lengthy batch job. This stored procedure is called from a trigger you do not want to slow the data entry process you do not want trigger to wait for this batch job to finish before it completes itself what you can do to speed up the process?
How do I start sql server 2017?
What are the different types of subquery?
what is spatial nonclustered index
What are the kinds of subquery?
What is self contained sub query?