adspace
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 self contained sub query?
Why we use the openxml clause?
What is clustered index
If you're given a raw data table, how would perform etl (extract, transform, load) with sql to obtain the data in a desired format?
Why use identity in sql server?
What is temporary table in sql server? Why we use temp table?
What are the kinds of subquery?
If any stored procedure is encrypted, then can we see its definition in activity monitor?
How to enter binary string literals in ms sql server?
How to convert numeric expression data types using the cast() function?
What are the different types of subquery?
Disadvantages of the indexes?
explain different types of backups avaialabe in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration
What is a view in sql?
What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?