Delete duplicate records from oracle table

Delete duplicate records from oracle table


Note: please before executing this query take data backup.

Example I:
Delete from employees
where rowid in
(select rowid
from
(select first_name, last_name, rowid,
row_number() over
(partition by first_name, last_name order by employee_id)
stf_row
from  employees)
where stf_row > 1);


Example  II :

Delete FROM
   Employees A
WHERE
  a.rowid >
   ANY (
     SELECT
        B.rowid
     FROM
        Employees B
     WHERE
        A.First_name = B.First_Name
     AND
        A.last_name = B.Last_Name
        );


 Example  III :

 Delete from
  Employees A
  Where rowid <> (
            SELECT
             Max(rowid)
            From
            Employees B
            Where
            B.First_Name = A.First_Name
            AND
            B.Last_Name = A.Last_Name )

Result



Leave a Reply

Your email address will not be published. Required fields are marked *