Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Creating Columns out of entries from a joined table
Hi,
I have the following problem :
Table A Table B NR ... NR DEVICE TIME NR1 NR1 Dev1 T1
I want to create a select statement that gives me the following :
NR Dev1 Dev2
NR1 T1 -
For devices that exist in table B I use the statement
select A.NR, B1.TIME as Dev1
from A, B B1
where
B1.NR=A.NR
and B1='Dev1' ;
The problem is the following :
When I'm looking for a device which is not in table B for an entry in
table A (here Dev2 for NR1) and I treat it in the same way as mentioned
above I get an empty row.
select A.NR, B1.TIME as as Dev2
from A, B B1
where
B1.NR=A.NR
and B1='Dev2';
The desired behavior would be to receive the following
NR Dev2
NR1 null/empty/or whatever
How can I achieve this ?
I tried it with joins which works fine in ANSI SQL like
SELECT A.NR, B1.TIME as Dev2
FROM A LEFT JOIN B AS B1 ON (A.NR=B1.NR and (B1.DEVICE='Dev2' or B1.NR is
null));
But I was not able to translate this statement into Theta-Style for Oracle (+)
Any ideas ?
Thanks in advance
Reiner
-- * HP : www.unke.net *Received on Thu May 02 2002 - 10:17:58 CDT