Wednesday, 23 August 2017

how to see and delete duplicate rows .

select mgr,count(*) from emp
group by mgr
having count(*) >1;

MGRCOUNT(*)
78393
76985
75662

DELETE FROM your_table
WHERE rowid not in
(SELECT MIN(rowid)
FROM your_table
GROUP BY column1, column2, column3);

example-
select * from emp
where rowid not in (select min(rowid) from emp group by mgr);
EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7844TURNERSALESMAN769808-09-19811500030
7900JAMESCLERK769803-12-1981950 30
7654MARTINSALESMAN769828-09-19811250140030
7698BLAKEMANAGER783901-05-19812850 30
7902FORDANALYST756603-12-19813000 20
7521WARDSALESMAN769822-02-1981125050030
7782CLARKMANAGER783909-06-19812450 10

No comments:

Post a Comment