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


Please Help Members By Posting Answers For Below Questions

What is self contained sub query?

1141


Why we use the openxml clause?

1080


What is clustered index

1087


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?

1048


Why use identity in sql server?

1202


What is temporary table in sql server? Why we use temp table?

1023


What are the kinds of subquery?

1109


If any stored procedure is encrypted, then can we see its definition in activity monitor?

1072


How to enter binary string literals in ms sql server?

1246


How to convert numeric expression data types using the cast() function?

1151


What are the different types of subquery?

1235


Disadvantages of the indexes?

1225


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

1134


What is a view in sql?

1043


What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?

1200