1

我试图为我的左连接添加别名,以便我可以在同一个表(不同的键)上进行两个连接,但遇到了这个问题。我已将查询剥离到问题所在,以保持简单。

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

当我运行此查询时,我得到

1054 - 'on 子句'中的未知列'exchange_rates.id'

但是,如果我删除别名,它看起来像这样......

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

此查询运行良好...?

4

1 回答 1

1

如果你添加一个alias,你应该在你的join.

SELECT stock_items.id AS stockid, exr.rate AS rate
FROM stock_items
LEFT JOIN exchange_rates exr ON stock_items.currency = exr.id
于 2012-08-23T12:11:50.037 回答