Subject Re: [firebird-support] outer join help
Author Alexandre Benson Smith
Ed Dressel wrote:
> This is pretty simple, I seldom use outer joins. I need two levels of
> outer joins:
>
> Table1
> + Table2 [outer]
> + Table3 [outer]
>
> but I can not get the second one to work. My SQL is below:
>

My SQL ??? This was not a FB forum ???? :-))))

> select ...
> from Table1 T1 left join Table2 on T1.Table1_ID = Table2.Table1_ID,
> Table2 outer join Table3 T3 on Table2.Table2_ID = T3.Table2_ID
> where ...
>
> I've tried various forms of it, some which lock up my application.
>

your problem lies here:

select ...
from
Table1 T1 left join

// ok, an left outer join here between T1 and T2


Table2 on T1.Table1_ID = Table2.Table1_ID,
// in the above line lies the problem the coma indicates a SQL89 join and
// because you specify no condition in the where it becomes a cross join !!!!
// a Cross join between the T1 and T2 with outer join stream and the T2 and T3 outer join strem

Table2 outer join Table3 T3 on Table2.Table2_ID = T3.Table2_ID
where ...



> What is the SQL?
>
>
>
try this one:

select ...
from
Table1 T1 left join
Table2 on T1.Table1_ID = Table2.Table1_ID left join
Table3 T3 on Table2.Table2_ID = T3.Table2_ID
where ...

see you !


--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br