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 is sql server query analyzer?
What is dynamic cursor in SQL SERVER?
What is the difference between composite index and covering index?
What is truncate table?
System variable and temporary variables
What are sub reports and how to create them?
What are different types of statement?
Can a table have 2 foreign keys?
What is 'Join' and explain its various types.
How to select some specific rows from a table in ms sql server?
Explain the difference between cross join and full outer join?
What are the types of user defined functions in sql server?
Difference between drill down and drill through report.
What is difference between commit and rollback when used in transactions?
List the advantages of using stored procedures?