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

时间:2022-10-18 18:16:30

Currently I am doing this query:

目前我在做这个查询:

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

However, I want to retrieve records from table "a" even if "a.c = null", which is not retrieved due to the join between "a" and "c".

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

I have found information about the "left join" (http://www.w3schools.com/sql/sql_join_left.asp) but I don't know how to do it when the query involves more than two tables like in this case.

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

Any help or guidance will be greatly appreciated.

任何帮助或指导将不胜感激。

1 个解决方案

#1


32  

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

#1


32  

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