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
How do I repair damaged sql server mdf file database? In previous day my mdf file has got damage due to unknown reasons then I used dbcc chekcdb command but it failed, MDF file is important for me, I don’ know that how to get back mdf file data. Please anyone suggest me?
Define Business Edition in SQL Azure?
Tell me time data type, datetime2, datetimeoffset data type in sql server 2008?
Explain aggregate functions?
How to change the name of a database user?
What are the requirements to use odbc connections in php scripts?
What are the differences between web role and worker role?
What is collation?
What is a data source or ds? : sql server analysis services, ssas
How to get @@error and @@rowcount at the same time?
What is the difference between insensitive and scroll cursor?
How to change the data type of an existing column with "alter table" statements in ms sql server?
What is the new security features added in sql server 2016? : sql server security
Explain the etl (extraction, transformation, and loading)?
What is the difference between clustered index and primary key?