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 define output parameters in stored procedures?
how you can deploy an ssrs report?
What is the difference between the 2 operating modes of database mirroring?
What are the types of resultset?
Define full outer join in sql server joins?
How to list all dsn entries on your local machine using odbc_data_source()?
Explain syntax for disabling triggers?
What is openxml in sql server?
What is difference between rownum and rowid?
How would you use user_constraints table in DB?
Can a stored procedure call itself or a recursive stored procedure? How many levels of sp nesting is possible?
Explain nested join?
What do you mean by a dependent functionality in a build?
What are three ways you can use an identity value inside a trigger? Why would you prefer one way over another?
Does windows server 2016 come with sql server?