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
What is sql collation?
How to use "begin ... End" statement structures in ms sql server?
What are the types of dml?
Explain system scalar functions?
What sql server means?
Is it possible to call a stored procedure within a stored procedure?
How to see existing views in ms sql server?
What does Master database contains?
What is the difference RDBMS and Graph Database?
What is an etl file?
What are the steps to process a single select statement?
Do you know what are pages and extents? : SQL Server Architecture
Can we use where and having clause together?
Explain the different index configurations a table can have?
What do you understand by recursive stored procedures?