MySQL 如何对 2 个以上的表进行 LEFT JOIN?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7980052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:31:27  来源:igfitidea点击:

How to do LEFT JOIN with more than 2 tables?

mysqlsqlleft-join

提问by aleafonso

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".

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

I have found information about left joinbut I don't know how to do it when the query involves more than two tables like in this case.

我找到了有关的信息left join,但当查询涉及两个以上的表时,我不知道该怎么做,就像在这种情况下一样。

回答by Chris J

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