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 / shankaranarayanan v
while exists(select count(*) from employee group by empname having count(*)>1)
begin
delete top(1) from employee where empname in
(
select min(empname) as deletedname
from employee
group by empname
having count(*)>1
)
end
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
How can we rewrite sub-queries into simple select statements or with joins?
How do I manually uninstall an instance of sql server 2016?
How to specify the collation for a character data type in ms sql server?
What are the built in functions in sql server?
What is difference between aggregate and analytic function?
How do I delete a sql server database?
What is use of attributehierarchyenabled? : sql server analysis services, ssas
Explain how to send email from sql database?
How do I find the size of a sql server database?
What is Cross Join and in which scenario do we use Cross Join?
What are the features of Embedded SQL
your distribution database is full what will u do
in a table is b in column k (manikanta,sivananda,muralidhar) i want result like (mnikanta,sivnanda,murlidhar) please slove it
Do you know how to send email from database?
What is the difference between join and inner join?