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 are the grouping functions?
Tell about MOM Tool(Microsoft Operator Manager)?
How to view existing indexes on an given table using sp_help?
What are the different types of join?
What is the contrast between sql and mysql?
What is transaction server auto commit?
Do you know what are acid properties of transaction?
when you create a database how is it stored? : Sql server database administration
What is the meaning of resultset type_scroll_insensitive?
What gets stored inside msdb database?
How to list all triggers in the database with sys.triggers in ms sql server?
What is a matrix in ssrs?
Explain transaction server auto commit?
How to enforce security in sql server? : sql server security
Explain how to send email from sql database?