suppose there is a employee table containing columns name, id and salary having 2 or more than two rows with same values in all three rows...then how to write a query to delete duplicate rows..
Here is a nice way if you use Sql Server
with duplicates as
(select * ,ROW_NUMBER() over(
partition by id,name, salary
order by id,name, salary) rownum
from Person)
delete from duplicates where rownum > 1
assuming ID is the primary key:
delete P
from Person P right outer join
(
select name, min(id) as id
from Person
group by name
) unique_people
on P.id = unique_people.id
where P.id is NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With