I'm not used to the 'as' keyword and I thought it would be a nice idea to use it. So why do I get an 'unknown column' (eid) error? I use mysql...

select t1.index as eid, t1.col1 as col1, t1.col2 as col2, 
t2.index, t2.col1, t2.col2,
t3.index, t3.col1, t3.col2 
from table1 t1 
left join table2 t2 on t2.index=eid
left join table3 t3 on t3.index=eid;

The full statement is too long to present here without boring everybody. The column and table names are random.


1 Answer 1


A relational sub-select is logically processed in the following sequence:

  1. FROM clause
  2. WHERE clause
  3. GROUP BY clause
  4. HAVING clause
  5. SELECT clause
  6. ORDER BY clause
  7. LIMIT...OFFSET clause or the equivalent

Subsequently, the column labels defined in the SELECT clause are not yet known when the FROM clause, containing the joins in your example, is dealt with.

Not the answer you're looking for? Browse other questions tagged or ask your own question.