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

What is sub-query in sql server?

666


How to find index size for each index on table?

583


How to use go command in "sqlcmd"?

642


What are functions in the sql server?

603


Do you know hot add cpu in sql server 2008?

538






Does server sql treat char as a variable-length or fixed-length column?

582


Describe how to use linked server?

542


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

484


What are the advantages of paper records?

556


What are the system database in sql server 2008?

574


What are the aggregate and scalar functions?

523


Where do we use trace frag?

572


What is instead of trigger sql server?

497


Where are full-text indexes stored?

571


How can I add Reporting Services reports to my application?

91