Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Remove duplicates based on a condition

S62065Jan 15 2011 — edited Jan 16 2011
Hi all,

I need help on a query to remove duplicates based on a condition.

E.g. My table is

FE CC DATE FLAG
----------------------------------------
FE1 CC1 10/10 FB
FE1 CC1 9/10 FB
FE1 CC1 11/10 AB
FE1 CC2 9/10 AB
FE1 CC2 10/10 FB
FE1 CC2 11/10 AB

I want to remove all duplicate rows on FE and CC based on the below condition :
DATE <MAX(DATE) WHERE FLAG='FB'

That means I want to remove the row FE1 CC1 9/10 FB
but not the rows
FE1 CC1 10/10 FB
and
FE1 CC1 11/10 AB
as only the row FE1 CC1 9/10 FB has date <MAX(DATE) WHERE FLAG='FB'.
Similarly I want to keep
FE1 CC2 10/10 FB
FE1 CC2 11/10 AB
but not
FE1 CC2 9/10 AB

Many thanks.
This post has been answered by Eight Six on Jan 15 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2011
Added on Jan 15 2011
5 comments
1,590 views