Cannot reference table name in ON expression after nominating table alias in JOIN clause (error 1054 - Unknown column)
I was trying to add aliases to my left joins so that I could do two joins on the same table (different key) but ran in to this problem. I've stripped down the query to where the problem is to keep things simple.
SELECT stock_items.id AS stockid, exchange_rates.rate AS rate
FROM stock_items
LEFT JOIN exchange_rates AS exr ON stock_items.currency = exchange_rates.id
When I run this query I get
1054 - Unknown column 'exchange_rates.id' in 'on clause'
However, the query runs fine if I remove the alias like this:
SELECT stock_items.id AS stockid, exchange_rates.rate AS rate
FROM stock_items
LEFT JOIN exchange_rates ON stock_items.currency = exchange_rates.id