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 does select 1 mean?

521


What is subreport?

96


What are the differences between INNER JOIN, LEFT JOIN and RIGHT JOIN in SQL Server?

608


what are the different types of replication you can set up in sql server? : Sql server database administration

506


How sql server enhances scalability of the database system?

579






What is federation member?

91


What is plan freezing?

575


Can you pass expressions to function parameters?

531


Write an sql query to sort a table according to the amounts in a row and find the second largest amount.

552


What does truncate do?

526


What is a cursor, index in sql?

565


What is the difference between Triggers and Stored Procedure?

561


What is default constraint?

534


Explain the purpose of indexes?

532


How to get a list of table columns using the "sp_columns" stored procedure in ms sql server?

549