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 meant by indexing?
What is the status of services on passive node for failover cluster in sql server? : sql server database administration
Explain insert into select statement?
What action plan is preferred if sql server is not responding?
What language is sql server written in?
What is Federation Root Database?
What options are available to audit login activity? : sql server security
What is the difference between row_number and dense_rank?
What are the options which must be set to allow the usage of optimistic models?
Explain activity monitors
What programming language would you use to create embedded functions in ssrs?
Can the query output be sorted by multiple columns in ms sql server?
Where are stored procedures in sql server?
Why should one not prefix user stored procedures with ‘sp_’?
How to convert character strings into numeric values?