JOIN三个表 [英] JOIN three tables

查看:160
本文介绍了JOIN三个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检索两组信息(在一个查询中的图的红色和蓝色部分。

I am trying to retrieve two sets of information (the red and blue portions of the diagram in the one query.

我想我可以使用sql但如果TableC没有记录,它不返回任何内容,如果TableC没有记录,我仍然希望这个查询返回我的结果,如蓝色区域所示。

I thought I could do it using the sql as stated below but it does not return me anything when TableC has no records. If TableC has no records, I would still want this query to return me the results as indicated by the BLUE area.


SELECT A. * FROM TableA A

SELECT A.* FROM TableA A

JOIN TableB B ON(A.id = B.a_id)

JOIN TableB B ON (A.id = B.a_id)

JOIN TableC C ON(A.id = C.a_id)

JOIN TableC C ON (A.id = C.a_id)

感谢提前=]

推荐答案

尝试类似这样的

SELECT A.* FROM TableA A
LEFT OUTER JOIN TableB B ON (A.id = B.a_id)
LEFT OUTER JOIN TableC C ON (A.id = C.a_id)
WHERE B.a_id IS NOT NULL 
  OR c.a_id IS NOT NULL

这篇关于JOIN三个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆