I had the below query working in mysql 4.1, but does not in 5.0:
SELECT * FROM email e, event_email ee
LEFT JOIN member m on m.email=e.email
WHERE ee.email_id = e.email_id
The error: 1054 (Unknown column 'e.email' in 'on clause')
I had the below query working in mysql 4.1, but does not in 5.0:
SELECT * FROM email e, event_email ee
LEFT JOIN member m on m.email=e.email
WHERE ee.email_id = e.email_id
The error: 1054 (Unknown column 'e.email' in 'on clause')
You can only refer the tables previously joined with the
JOIN
clause in theON
clause.This can be illustrated better if I put the parentheses around the
ANSI JOINS
in your original query:As you can see, there is no source for
e.email
inside the parentheses: that's why it could not be resolved.From MySQL documentation page
Previously, the comma operator (,) and JOIN both had the same precedence, so the join expression t1, t2 JOIN t3 was interpreted as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the expression is interpreted as (t1, (t2 JOIN t3)). This change affects statements that use an ON clause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.
Example:
Previously, the SELECT was legal due to the implicit grouping of t1,t2 as (t1,t2). Now the JOIN takes precedence, so the operands for the ON clause are t2 and t3. Because t1.i1 is not a column in either of the operands, the result is an Unknown column 't1.i1' in 'on clause' error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for the ON clause are (t1,t2) and t3:
Alternatively, avoid the use of the comma operator and use JOIN instead:
This change also applies to statements that mix the comma operator with INNER JOIN, CROSS JOIN, LEFT JOIN, and RIGHT JOIN, all of which now have higher precedence than the comma operator.
The answer would be to place the JOIN statement directly after the table in the FROM statement, because that is the table you are joining on: