Professional Documents
Culture Documents
5 Ways To Delete Duplicate Records
5 Ways To Delete Duplicate Records
In Oracle there are many ways to delete duplicate records. Note that below
example are described to just explain the different possibilities.
Consider the EMP table with below rows
create table emp(
EMPNNO integer,
EMPNAME varchar2(20),
SALARY number);
10
11
12
12
12
13
14
15
Bill 2000
Bill 2000
Mark 3000
Mark 3000
Mark 3000
Tom 4000
Tom 5000
Susan 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
SQL > delete from emp e1
where rowid not in
5. Using group by
Consider the EMP table with below rows
10
11
12
13
Bill 2000
Bill 2000
Mark 3000
Mark 3000