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
Can you explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?
how to define testing of network layers? : Sql server database administration
How to call stored procedure using http soap?
How do I find the sql server version?
What does the on update no action do?
Do you know what are the differences between lost updates and uncommitted dependencies?
What is the main purpose of having conversation group?
Can sql servers link to other servers like oracle?
How to truncate the log in sql server 2012? : sql server database administration
Explain what are the basic functions for master, msdb, model, tempdb databases?
What do you mean by acid?
can you implement data mining in SSRS?
What is a covering index?
What is view in sql?
What will happen if a column containing char type data is changed to the nchar data type?