-- error: is T1 out of scope in on clause for T3?
select *
from lateral(values (1)) T1(a), lateral(values(1)) T2 (a)
left outer join lateral(values(2)) T3(a)
on T1.a = T3.a
SQL0338N An ON clause associated with a JOIN operator or in a MERGE
statement
is not valid. SQLSTATE=42972
-- using T2 in on clause works
select *
from lateral(values (1)) T1(a),
lateral(values(1)) T2 (a)
left outer join lateral(values(2)) T3(a)
on T2.a = T3.a
A A A
----------- ----------- -----------
1 1 -
-- of course using T1 works if T1 and T2 are swapped
select *
from lateral(values (1)) T2(a), lateral(values(1)) T1 (a)
left outer join lateral(values(2)) T3(a)
on T1.a = T3.a
A A A
----------- ----------- -----------
1 1 -
-- and using explicit join all the way works as well
select *
from lateral(values (1)) T1(a)
inner join lateral(values(1)) T2 (a)
on T1.a = T2.a
left outer join lateral(values(2)) T3(a)
on T1.a = T3.a"
A A A
----------- ----------- -----------
1 1 -
/Lennart
I forgot the where clause for the 3 first examples, but since there is
only one row in T1 and T2 that matches, it should not make a
difference.
/Lennart
Cheers
Serge
--
Serge Rielau
SQL Architect DB2 for LUW
IBM Toronto Lab
Well, It is not critical, and I don't like the idea of mixing join
styles in the same query, but perhaps I should open a PMR then.
Meanwhile I was merely interested in comments on whether the
construction is legal or not.
/Lennart