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
Explain the different types of backups available in sql server? : sql server database administration
What is sql injection and why is it a problem? : sql server security
Tell me what are the advantages of using stored procedures?
How to maintain a fill factor in existing indexes?
How do I schedule a sql server profiler trace?
How to change the password of a login name in ms sql server?
What is extended stored procedures?
Can group functions be mixed with non-group selection fields in ms sql server?
Why use cursor in sql server?
hi, how to link a text file and a .rpt file in my tables of sql server and to retrieve those records for further use. reply me as soon as possible.
What is analysis service repository?
Please explain go command in sql server?
How to receive output values from stored procedures?
What are different types of table joins?
Name few of the dcl commands in sql?