Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Deleting Records

969952Dec 20 2012 — edited Dec 20 2012
Hi All,

I have a table and it's having duplicate records.

for one particular employee, he is having multiple records with the same data in the table
EMPNO    ENAME     JOB     SAL     DOB
-------------------------------------------------------
1               A           X        100     1956
2               B           Y        200     1974
1               A           X        100     1956
3               C           Z        300     1920
1               A           X        100     1956
2               B           Y        200     1974
3               C           Z        300     1920
3               C           Z        300     1920
3               C           Z        300     1920
2               B           Y        200     1974
2               B           Y        200     1974
2               B           Y        200     1974
1               A           X        100     1956
like this am having multiple times the duplicates.

I have written the below query to delete the duplicate records. But it is deleting only one record (if we have 5 duplicates it is deleting only 1 ). But I am looking to delete if we have 5 duplicates need to delete 4 duplicates and keep 1 record in the table. Can you please help me out for this.
query which am using to delete the duplicates is 

DELETE FROM Table1 a  
WHERE ROWID IN (SELECT MAX(ROWID)  
                FROM Table2 b 
                WHERE a.ID = b.ID);  
it is deleting only one row but I want to delete 4 records out of 5 and keep one record.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 17 2013
Added on Dec 20 2012
12 comments
723 views