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
Do you know what is difference between index seek vs. Index scan?
Why does sql studio use a single registered database repository? : sql server management studio
Can the “if update (colname)” statement be used in a delete trigger?
What is normalization? Explain different forms of normalization?
Explain magic tables in sql server?
What are the types of subquery?
Is it possible in sql table to have more than one foreign key?
IF more than one Site is accessing the same Database server and I want to move the DB with Minimum down time? How will you do
Explain the stored procedure?
What are the different types of indexes?
What is the syntax to execute the sys.dm_db_missing_index_details?
Explain Capacity planning to create a database? and how to monitor it?
Explain trigger and trigger types?
Do you know what is a linked server in sql server?
Explain cursor as data base object?