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
How to assign null values to variables or columns?
Why should you use or avoid select * statements?
what types of replication are supported in sql server? : Sql server database administration
What does it mean to normalize data?
How to create a simple stored procedure in ms sql server?
What is buffer cash and log cache in sql server?
What are ddl triggers and types of ddl trigger?
How to create a user name in a database?
What is local temp table?
Mention the differences between local and global temporary tables.
Explain the difference between functions and stored procedures in sql server?
What are sql server procedures?
where the connection string store in the database
Do you know how to implement service broker?
How adventureworkslt tables are related?