How to remove duplicate records from a Table?
If you want to remove duplicate rows from a Table and want to leave only unique records in a Table then choose any one of the following method to delete duplicate rows.
SQL> DELETE FROM SAMPLE A WHERE ROWID > (SELECT MIN(ROWID) FROM SAMPLE B WHERE A.ID=B.ID);
1 row deleted.
Note: This method is not preferable because here you have to drop the table from database and that is not possible on any production database.
SQL> CREATE TABLE SAMPLE2 AS SELECT DISTINCT * FROM SAMPLE;
SQL> DROP TABLE SAMPLE;
SQL> RENAME SAMPLE2 TO SAMPLE;
SQL> DELETE FROM SAMPLE S1
WHERE EXISTS (SELECT ‘X’ FROM SAMPLE S2
WHERE S2.ID=S1.ID AND S2.ROWID>S1.ROWID);
You can choose Method-1 or Method-3 to delete duplicate rows from a table.
What is the Difference between Truncate and Delete in Oracle
If you know any other method to eliminate duplicate rows from a Table, please write them on comment section. We will definitely incorporate them in our article.