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 is subquery in sql?
What is the syntax to execute the sys.dm_db_missing_index_details?
Explain can SSRS reports Cache results?
Can sub report data source be different from that of the parent report?
What is store procedure? How do they work?
Why are sql functions used?
Does the unique constraint create an index?
What is rolap and its advantage? : sql server analysis services, ssas
Explain the truncate command? : SQL Server Architecture
What is the process of normalization?
What guidelines should be followed to help minimize deadlocks?
What is pivot and unpivot?
In what version of sql server were synonyms released?
How do I view a script in sql server?
What are 3 ways to get a count of the number of records in a table?