Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: oracle SQL question..
In article <6ki3m2$7sd$2_at_engnews2.Eng.Sun.COM>, gosar_at_EBB.Eng.Sun.COM wrote:
> Hi,
>
> I have table ....
>
> KC MKT PLT QTY
> ---------- ---------- --- ----------
> 100 M1 P1 1
> 100 M1 P1 2
> 100 M1 P1 3
> 200 M2 P1 1
> 300 M3 P3 1
> 200 M2 P2 1
> 100 M1 P2 1
>
> I want to select everything which is in PLT='P1' and
> only those records from other PLT's which have different
> combination of "KC, MKT and QTY fields"....
>
> snip
select ...
from your_table
where plt = 'P1'
UNION
select ...
from your_table T1
where plt <> 'P1'
and not exists
(select null from your_table T2
where T2.plt = 'P1'
and (T2.kc,T2.mkt,T2.qty) in ((T1.kc,T1.mkt,T1.qty)));
HTH
-- ChrysalisReceived on Thu May 28 1998 - 00:00:00 CDT