Professional Documents
Culture Documents
5 Ways To Delete Duplicate Records
5 Ways To Delete Duplicate Records
records Oracle
Posted on January 29, 2013by sqlandplsql
12
12
12
13
14
15
Mark
Mark
Mark
Tom
Tom
Susan
3000
3000
3000
4000
5000
5000
1. Using rowid
SQL > delete from emp
where rowid not in
(select max(rowid) from emp group by
empno);
This technique can be applied to almost
scenarios. Group by operation should be on
the columns which identify the duplicates.
2. Using self-join
Bill 2000
Bill 2000
Mark 3000
Mark 3000
group by empname,salary
);
This technique is only applicable in few
scenarios.
Always take extra caution while deleting
records.
1. First identify the duplicates using select.
2. Double verify those are actual
duplicates or not
3. Take backup if necessary
4. Apply commit only if you are sure.