从两个表加入然后从结果加入到第三个表mysql

时间:2014-11-24 21:36:50

标签: php mysql sql join

我试图从两个表中获取JOIN并将结果表与第三个表一起加入但是它的抛出错误,让我知道我在这里做错了什么 -

SELECT e.id as e_id, e.name as e_name, e.artist_id as e_artist_id, e.event_date as e_date, 
        v.id as v_id, v.name as v_name, v.address as v_address, v.latitude as v_latitude, v.longitude as v_longitude 
FROM events e 
LEFT JOIN venues v 
ON e.venue_id = v.id WHERE v.id = 12
LEFT JOIN artists a
ON e.artist_id = a.id

1 个答案:

答案 0 :(得分:1)

您需要将WHERE子句更改为AND -

SELECT e.id as e_id, e.name as e_name, e.artist_id as e_artist_id, e.event_date as e_date, 
        v.id as v_id, v.name as v_name, v.address as v_address, v.latitude as v_latitude, v.longitude as v_longitude 
FROM events e 
LEFT JOIN venues v 
ON e.venue_id = v.id AND v.id = 12
LEFT JOIN artists a
ON e.artist_id = a.id