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 / sunil
set rowcount 1 -- set row count 1
delete a from Employee a
where (select count(*) from Employee e where e.empname =
a.empname) > 1
while @@rowcount > 0
begin
delete a from Employee a
where (select count(*) from Employee e where e.empname =
a.empname) > 1
end
set rowcount 0
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Which tcp/ip port does the sql server run on? How can it be changed?
What is sql profiler. What are the default templates with it? : sql server database administration
We need to perform what steps in the following order to work with a cursor?
Create and insert into temp table in sql server?
What is user-defined functions? What are the types of user-defined functions that can be created?
How to resolve the orphan use problem? : sql server security
What is the difference between drop table and truncate table?
What is the purpose of forms?
How to apply cascading referential integrity in place of triggers?
What are different types of raid levels?
What is mscorsvw.exe - process - microsoft .net framework ngen?
how to restart sql server in single user mode? How to start sql server in minimal configuration mode? : Sql server database administration
How to send email from database?
What is an etl file?
Explain what are magic tables in sql server?