Remove duplicates based on a condition
S62065Jan 15 2011 — edited Jan 16 2011Hi 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.