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 / devender kumar

This query is for sql server 2005 and higher version of sql
server. It will not run on older versions.



with myCTE as(
select row_number() over( partition by empname order by
empname) as myCount from Employee
)delete from myCTE where myCount >3

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to stop a loop early with break statements in ms sql server?

576


When we should use @@error?

543


What is self join in sql server joins?

562


How to create new table with "create table" statements?

564


Comment,Datatypes are unlimited

1632






What is factless fact table? : sql server analysis services, ssas

569


What are the advantages of user-defined functions over stored procedures in sql server?

466


What is the correct order of the logical query processing phases?

529


How to find out what is the default collation in a database?

634


What is the usage of sign function?

598


Do you think BCNF is better than 2NF & 3NF? Why?

797


What is bit data type?

630


How to list all login names on the ms sql server?

539


What programming language would you use to create embedded functions in ssrs?

122


What is merge statement?

629