May 7, 2011

How do I eliminate the duplicate rows ?

SQL> delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);

Example.

Table: Emp

Empno Ename
101     Ram
102     Tiger
103     Scott
104     Bikram
105     Scott

SQL:delete ename from emp a where rowid < ( select max(rowid) from emp b where a.ename = b.ename);

The output like,

Empno Ename
101     Ram
102     Tiger
103     Scott
104     Bikram

Note: Please read the Co-related sub query Concepts.

No comments:

Post a Comment