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
What are translations and its use? : sql server analysis services, ssas
What are the new data types are introduced in sql 2000?
How to create a user to access a database in ms sql server using "create user" statements?
How to drop an existing user defined function in ms sql server?
Which sql server is best?
How to compose an inquiry to demonstrate the points of interest of an understudy from students table whose name begins with k?
What is reference section?
Can we perform backup restore operation on tempdb?
You want to generate a report that is formatted as a chart. Can you use the report wizard to create such a report?
What is the difference between createstatement and preparedstatement?
What is difference between count (*) and count column?
What are the main sources of data?
What is change data capture (cdc) feature?
Why truncate is ddl?
What is data source view or dsv? : sql server analysis services, ssas