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
What is a sql join?
What are alternate keys?
Define msdb database?
Give main differences between "Truncate" and "Delete".
What is apply operator in sql?
What is the cartesian product of the table?
What is forward - only cursors / read only cursor?
What are cursors and when they are useful?
Explain important index characteristics?
How to create an index on an existing table in ms sql server?
How can sql server instances be hidden?
What is dbcc updateusage?
What are diverse clauses that form a part of sql?
What is the full form of dql?
How to get all stored procedures in sql server?