【问题标题】:How to do LEFT JOIN with more than 2 tables?如何对超过 2 个表进行 LEFT JOIN?
【发布时间】:2011-12-20 06:31:13
【问题描述】:

目前我正在做这个查询:

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”之间的连接而无法检索到。

我找到了有关left join 的信息,但是当查询涉及到两个以上的表时,我不知道该怎么做。

【问题讨论】:

  • 你不能使用两个连接语句吗? SELECT xyz FROM table_a LEFT JOIN table_b ON xyz = xyz LEFT JOIN table_c ON xyz = xyz看看MySQL manual
  • 你知道这个问题需要什么吗?更多重复的答案;)

标签: mysql sql left-join


【解决方案1】:
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

【讨论】:

  • 如果number 的结果中没有任何内容,但您仍需要从customer 获取结果,同时仍向左加入numbergroup,该怎么办?这在这种情况下不起作用!
猜你喜欢
  • 1970-01-01
  • 2022-06-17
  • 2021-03-08
  • 1970-01-01
  • 1970-01-01
  • 2011-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多