Removal of Duplicates - How To Do It

BANK
SN    AMT
  1    100
  2    300
DELETE BANK B1 WHERE B1.ROWID<ANY
(SELECT B2.ROWID FROM BANK B2
WHERE B1.SN=B2.SN
AND B1.AMT=B2.AMT) ;

Above query doesn't work for NULLS.  Can you do something about it without evaluating NULLs to some value[NVL(AMT, 0)]

Solution by Arun :

Basically it depend on business logic.
For below sample problem we can use the script as:

truncate table bank

create table bank (SN number(2),amt number(8,2));

insert into bank values(1,100);
insert into bank values(1,100);
insert into bank values(1,100);
insert into bank values(2,200);
insert into bank values(2,200);
insert into bank values(2,200);
insert into bank values(null,null);
insert into bank values(null,null);
insert into bank values(null,null);
insert into bank values(1,null);
insert into bank values(1,null);
insert into bank values(null,400);
insert into bank values(null,400);

DELETE from BANK B1 WHERE B1.ROWID not in 
(SELECT min(B2.ROWID) FROM BANK B2 WHERE B1.SN=B2.SN AND B1.AMT=B2.AMT
union
SELECT min(B2.ROWID) FROM BANK B2 where B2.SN is null and B2.AMT is not null
union
SELECT min(B2.ROWID) FROM BANK B2 where B2.SN is not null and B2.AMT is null
union
SELECT min(B2.ROWID) FROM BANK B2 where B2.SN is null and B2.AMT is null
) ;

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.