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 are the dis_advantages of stored procedures, triggers, indexes?

1678


What is multi-statement table-value user-defined function?

529


You have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem?

562


What is 3nf normalization form?

554


In case you have filters in your report, when filters will be applied in cached report instance?

77






What is difference between commit and rollback when used in transactions?

488


How to receive output values from stored procedures?

470


What is the difference between osql and query analyzer?

539


What is explicit mode in sql server?

523


What is change data capture (cdc) in sql server 2008?

558


Can we perform backup restore operation on tempdb? : sql server database administration

579


What is the template in sql?

532


How is sql used in sql server?

493


You want to check the syntax of a complicated update sql statement without executing it. What command should you use?

480


Why do we use sql limitations? Which constraints can we use while making a database in sql?

555