如何使用超过2个表进行LEFT JOIN?

时间:2011-11-02 12:10:52

标签: mysql sql left-join

目前我正在进行此查询:

select a.x, b.x, c.x
from number as a, customer as b, numbergroup as c
where a.b = b.b and a.c = c.c and c.b = b.b

但是,我想从表“a”中检索记录,即使“a.c = null”,由于“a”和“c”之间的连接而未检索到该记录。

我找到了关于“左连接”的信息(http://www.w3schools.com/sql/sql_join_left.asp),但是当查询涉及两个以上的表时,我不知道怎么做这种情况。

非常感谢任何帮助或指导。

1 个答案:

答案 0 :(得分:36)

select a.x, b.x, c.x 
from number as a
left join customer as b on a.b = b.b
left join numbergroup as c on a.c = c.c and c.b = b.b