Deleting duplicate rows in the
table
I am searching for a way to delete the duplicate records
in a table..
Is anybody having efficient way to do it..?
Manoj Lonikar
The command is:
DELETE <duplicate_col_name> dv
FROM <table_name> a WHERE rowid <
(SELECT MIN(rowid)
FROM <table_name> b
WHERE a.dv = b.dv);
i.e. if the table name is emp and the dupicate column
value is ename:
DELETE ename
FROM emp a
WHERE rowid <
(SELECT MIN(rowid)
FROM emp b
WHERE a.ename = b.ename)
Another solution is:
delete from <table_name> where rowid not in (
select max(rowid) from <table_name> group by <duplicate_values_field_name>);
Rupjit
Have a Oracle Question
Do
you have an Oracle Question?
Oracle Books
Oracle
Certification, Database Administration, SQL, Application, Programming Reference
Books
Oracle Application
Oracle
Application Hints and Tips
Oracle Home
Oracle
Database, SQL, Application, Programming Tips
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
All product names are trademarks of their respective
companies.
The site www.erpgreat.com is not affiliated with or endorsed
by any company listed at this site.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
The content on this site may not be reproduced
or redistributed without the express written permission of
www.erpgreat.com or the content authors.
|