Bug #64595 som columns in inner joined table not accessible for outer join
Submitted: 8 Mar 2012 23:17 Modified: 9 Apr 2012 8:43
Reporter: Octaviano Ledesma Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version:5.5 OS:Linux
Assigned to: CPU Architecture:Any

[8 Mar 2012 23:17] Octaviano Ledesma
Description:
when several tables are inner joined (implicit notation) and are followed by an outer join, only the columns in the last inner joined table are available for use in the outer join
explicit inner joins don't seem to be a problem

How to repeat:

create table t1(f11 int, f12 int);
create table t2(f21 int, f22 int);
create table t3(f31 int, f32 int);
create table t4(f41 int, f42 int);

select t1.f11, t1.f12,t2.f22, t4.f42
from t1,  t2,  t3
left outer join t4
on t4.f41 = t1.f11
where t2.f21 = t1.f11
and t3.f31 = t1.f11
and t1.f12 > 4;

yields:
 Lookup Error - MySQL Database Error: Unknown column 't1.f11' in 'on clause'
while 
select t1.f11, t1.f12,t2.f22, t4.f42
from t1,  t2,  t3
left outer join t4
on t4.f41 = t3.f31
where t2.f21 = t1.f11
and t3.f31 = t1.f11
and t1.f12 > 4;

works just fine
so does

select t1.f11, t1.f12,t2.f22, t4.f42
from t1 
inner join t2
on t2.f21 = t1.f11
inner join t3
on t3.f31 = t1.f11
and t3.f32 = t2.f22
left outer join t4
on t4.f41 = t1.f11
where t1.f12 > 4

Suggested fix:
make all columns in inner joined tables available to subsequent outer joins
[9 Mar 2012 8:43] Valeriy Kravchuk
I think our manual (http://dev.mysql.com/doc/refman/5.5/en/join.html) explains cases you presented:

"However, the precedence of the comma operator is less than of INNER JOIN, CROSS JOIN, LEFT JOIN, and so on. If you mix comma joins with the other join types when there is a join condition, an error of the form Unknown column 'col_name' in 'on clause' may occur. Information about dealing with this problem is given later in this section."

Please, check.
[10 Apr 2012 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".