我如何正确创建一个SQL查询,该查询与四个表一起使用公共密钥连接

发布于 2025-01-25 19:02:57 字数 531 浏览 1 评论 0原文

我有四张桌子,有一个共同点。 四张桌子中的三张是第四张的小子集(主)。 我想加入表格,以便仅输出仅包含主表中的记录,这些记录是其他任何第四个:

例如:

我的最终结果应该看起来像:

“在此处输入图像说明”

我的问题是加入我使用的是,只给我所有表所共有的记录。 或只有一个表和主人的记录。

制定正确的加入的任何帮助都很棒!

I have four tables, that have a key in common.
three of the four tables are small subsets of the fourth,(master).
I want to join the tables such that only the output only contains records from the master table, that are on any of other fourth:

as an example:
enter image description here

My end result should look like this:

enter image description here

My problem is that joins I'm using, are giving me only the records that are common to all tables.
or records that are common to only one of the tables and the master.

Any help on formulating the correct join would be awesome!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗琴音 2025-02-01 19:02:57

三个左连接将产生您想要的结果。例如:

select a.*, b.color, c.size, d.weight
from a
left join b on b.id = a.id
left join c on c.id = a.id
left join d on d.id = a.id
where b.id is not null or c.id is not null or d.id is not null

编辑:根据要求添加上面的子句。

Three left joins will produce the result you want. For example:

select a.*, b.color, c.size, d.weight
from a
left join b on b.id = a.id
left join c on c.id = a.id
left join d on d.id = a.id
where b.id is not null or c.id is not null or d.id is not null

EDIT: Added WHERE clause above as requested.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文