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 'Join' and explain its various types.

804


What are logical/boolean operations in ms sql server?

723


What is a deadlock and what is a live lock?

752


What is mean by clustered index and non clustered index, give syntax of creation? : sql server database administration

782


What is the difference function and stored procedure?

720






How do I create a partition table in sql server?

730


Can we use max in where clause?

697


What are the security related catalog views? : sql server security

703


Do you know what are the properties of the relational tables?

790


Which tcl commands are available on the sql server?

773


What is the order in which the sql query is executed?

699


What is difference between temp table and cte?

720


you added a row to a view, but the row is not shown on the view. Explain how this can happen, and how you can remedy the situation

709


What are the export options of ssrs?

151


What is self contained sub query?

754