Home » SQL & PL/SQL » SQL & PL/SQL » inner join within an outer join
inner join within an outer join [message #21377] Tue, 30 July 2002 14:19 Go to next message
joins
Messages: 2
Registered: July 2002
Junior Member
I know someone had posted similar question before, however all the suggestions posted don't answer my question. So here it goes again:
I've the following SQL-92 standard query:
select T1.A from T1 left outer join (T2 inner join T3 on T2.B = T3.B) on T1.A = T3.A
Trying to run the following Oracle native sql does not return the correct result:
select T1.A from T1, T2, T3 where T2.B = T3.B and T1.A = T3.A(+)
Oracle seems to insist on doing the outer join first before the inner join. Anyway, 2 suggestions posted to the board involved: 1) create a VIEW for the inner join part and use the VIEW for outer join; 2) rewrite the inner join as derived table: select T1.A from T1, (select T3.A from T2, T3 where T2.B = T3.B) T where T1.A = T.A(+).
What I'm looking for is how to rewrite the Oracle native query, without using the 2 suggestions (no views, no use of derived table) to get the correct result. Can anyone help me?
Re: inner join within an outer join [message #21378 is a reply to message #21377] Tue, 30 July 2002 14:41 Go to previous messageGo to next message
ctg
Messages: 146
Registered: July 2002
Senior Member
SELECT t1.a
FROM t1, t2, t3
WHERE t1.a = t3.a(+)
and t2.b(+) = t3.b;

if you forget the 2nd (+), it ignores the outer join.
Re: inner join within an outer join [message #21386 is a reply to message #21377] Wed, 31 July 2002 09:09 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
If you have T1 outer join to T2 and T2 outer joins to T3 then you need to do as you say in (2) i.e. create an inline view.
T1----(+)T2-----(+)T3

select t1.x, v.y, v.z from t1, (select t2.y, t3.z from
t2, t3 where t2.joincol=t3.joincol (+)) v and t1.joicol=v.joincol (+);

If you have T1 outer joins to T2 and T1 outer joins to T3 then you don't have a problem.
T1----(+)T2

+-----(+)T3
Re: inner join within an outer join [message #21389 is a reply to message #21377] Wed, 31 July 2002 13:23 Go to previous message
joins
Messages: 2
Registered: July 2002
Junior Member
This query does not return the correct result if the select list also contains column from table t2 or t3.
Previous Topic: Row Selectivity for Indexes
Next Topic: Re: Loops and varchar parsing
Goto Forum:
  


Current Time: Thu Apr 25 18:39:45 CDT 2024