Could anyone clarify why order of tables in FROM matters if I mix old and new syntax for joining tables?
For example,
SELECT *
FROM table1 a, table2 b
INNER JOIN table3 c ON (c.a_id = a.id) -- error - a.id - invalid identifier
WHERE (a.id = b.a_id)
SELECT *
FROM table2 b, table1 a
INNER JOIN table3 c ON (c.a_id = a.id) -- ok, table1 a is the last in FROM
WHERE (a.id = b.a_id)
I'm not going to use such ugly queries, but I believe all tables specified in FROM should be visible to other parts of the query.
I don't think it's up to RDMS because SQLServer, Oracle, and Mysql behave the same way - error for first query, no error for second. I'm definitely missing something obvious, but I didn't find anything that describes why it works this way.
Thank you.
ON), not because of invalid identifier. At least I'm able to execute that querySELECT * FROM table1 a INNER JOIN table2 b INNER JOIN table3 c ON ( c.a_id = a.id )with Mysql 5.5. – a1ex07 Mar 10 '12 at 18:42ONclause is sufficient. – Martin Smith Mar 10 '12 at 19:00