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

Define compound operators?

527


What is the library index called?

578


In which tcp/ip port does sql server run? Can it be changed?

536


what is datawarehouse?

642


what are the core components of SSRS?

92






What are “phantom rows”?

1235


Call by value and call by reference in procedure and function, with NOCOPY.

827


What guidelines should be followed to help minimize deadlocks?

498


What samples and sample databases are provided by microsoft?

559


What is difference between getdate and sysdatetime in sql server 2008?

592


What do you understand by physical_only option in dbcc checkdb?

574


What are dml (data manipulation language) statements in ms sql server?

545


can an order by clause be used in a creation of a view?

686


How to create a trigger for insert only?

593


Explain what is row_number function?

554