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 / sumathy
Execute the following query for each duplicate value.
1.Delete duplicate of empname='A'
delete top(select count(*)-1 from employee where
empname='A') from employee where empname='A'
2.Delete duplicate of empname='D'
delete top(select count(*)-1 from employee where
empname='D') from employee where empname='D'
Is This Answer Correct ? | 9 Yes | 2 No |
Post New Answer View All Answers
What are the dis_advantages of stored procedures, triggers, indexes?
What is multi-statement table-value user-defined function?
You have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem?
What is 3nf normalization form?
In case you have filters in your report, when filters will be applied in cached report instance?
What is difference between commit and rollback when used in transactions?
How to receive output values from stored procedures?
What is the difference between osql and query analyzer?
What is explicit mode in sql server?
What is change data capture (cdc) in sql server 2008?
Can we perform backup restore operation on tempdb? : sql server database administration
What is the template in sql?
How is sql used in sql server?
You want to check the syntax of a complicated update sql statement without executing it. What command should you use?
Why do we use sql limitations? Which constraints can we use while making a database in sql?