adspace


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

do you know how to configure db2 side of the application? : Sql server database administration

1124


How to enter binary string literals in ms sql server?

1244


Why we use the openxml clause?

1079


what is the Ticketing tool used in Wipro technologies at Bangalore...???

8230


What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?

1197


You have a stored procedure, which execute a lengthy batch job. This stored procedure is called from a trigger you do not want to slow the data entry process you do not want trigger to wait for this batch job to finish before it completes itself what you can do to speed up the process?

1213


Equi join and non equi join is possible with sql server?

1134


How can we solve concurrency problems?

1122


How do I find the sql server version?

1102


How to rebuild the master database?

1166


What is the difference between upgrade and migration in sql server?

1184


Why use identity in sql server?

1199


explain different types of backups avaialabe in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration

1133


How to remove duplicate rows from table except one?

1088


Can we make the the chages By Using the Sql if u know any function or process please inform me Actuall result: BRK1 Break 1 Part 1 00:01:00:00 60 BRK1 Break 1 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 BRK2 Break 2 Part 2 00:01:00:00 60 BRK2 Break 2 Part 3 00:01:00:00 60 BRK3 Break 3 Part 1 00:01:00:00 60 BRK3 Break 3 Part 2 00:01:00:00 60 Desired O/P: BRK1 Break 1 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 Part 3 00:01:00:00 60

2295