![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhL4EusSLXHiLmguq8p065pIW3FSUPuD_0N0duh-hP-X4WNFo712jnDx462bEYbRE2cTriWI5f-NmiRWLdgn98c-kq9lxI8YXl0GOUyjkr4Lfm4iMaa2S5tP6kjKolOvVDktUJdtTXgxO-7/s400/deldup.png)
This logic was found on PL/SQL Pipeline:
To test, insert a duplicate 'SMITH' on the EMP TABLE:
Insert Into Emp Values(9999,'SMITH','CLERK',7902,'17-DEC-80',800,NULL,20);You can see what is happening in the above report, and how a record is being chosen for deletion by running the following query. Records are being ranked (and a RowId saved) by breaking all the employees into partitions based on their name, hire date, and department. Within each 'partition,' they are ordered by the Rowid.
Commit;
Select Rowid, Empno, EName, HireDate, Deptno,
Rank() Over (Partition By EName, HireDate, DeptNo
Order By Rowid)
As
Ranking
From Emp;
This sets us up the delete:
Delete From Emp
Where Rowid In
( Select Rowid
From
( Select Rowid,
Rank() Over (Partition By EName, HireDate, DeptNo
Order By Rowid)
As
Ranking
From Emp
)
Where Ranking > 1
);
The task of deleting the duplicate entries can be achieved by this following simple method......
ReplyDeleteDELETE FROM EMP A
WHERE ROWID!=(SELECT MAX(ROWID) FROM EMP B WHERE A.ENAME=B.ENAME);