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 / honey

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

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the purposes of floor and sign functions?

544


what is datawarehouse?

651


What is policy management?

585


What is inner join in sql server joins?

549


Why I am getting this error when renaming a database in ms sql server?

540






What is pivot and unpivot?

644


What are synonyms?

531


what is package and it uses and how can u call a package

1564


List layers of abstraction microsoft architectured to provide relational db through cloud platform ?

161


What new data source types were added in ssrs 2014?

108


Can we use trigger new in before insert?

519


Do you know what is raid and what are different types of raid configurations? : SQL Server Architecture

548


What are functions in the sql server?

610


How to view existing indexes on an given table using sp_help?

598


How to defragment table indexes?

556