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 raiserror in sql server?
How many servers can we create in a single subscription?
mention different types of relationships in the dbms?
How to modify an existing user defined function?
1 01 101 01010
Suppose we have a table "MyTable" containing 10 rows, what query should be executed to update the odd rows "Salary" as 9000?
What is a domain constraint give an example?
What’s the distinction between dropping a info and taking a info offline?
What are the system database in sql server 2008?
What is a result set object returned by odbc_exec()?
What are different replication agents and what's their purpose? : sql server replication
What do you mean by sql server agent?
What is a functions and types in sql server?
What is truncate table?
Explain primary key, foreign key and unique key?