以下连接等效吗?

发布于 2024-12-22 03:48:53 字数 588 浏览 4 评论 0原文

我对左连接运算符和右连接运算符有点困惑。

select  *
from    <left table> lt
    left join <right table> rt on lt.pk = rt.fk

我一直对连接的“左”侧究竟是哪一侧感到有点困惑。 “左连接”关键字左侧的表...是“左表”或者是 on 子句左侧的表 左表就像等于左侧的表符号。我读过的文章表明它应该是

但是...现在考虑以下 select 语句...

select  *
from    <some table> st
    inner join <left table> lt on st.pk = lt.fk
    left join <right table r on rt.fk = st.pk

在上面的代码中是左表?然而,考虑到前面的陈述,人们会这样认为,因为含糊不清或不明确(因为它实际上不是直接离开的)......我认为在 on 子句中指定“左表”会更有意义。

所以我的每一点似乎都在与这种逻辑作斗争......我需要一点澄清......请并谢谢。

I'm a little confused regarding the left and right join operators.

select  *
from    <left table> lt
    left join <right table> rt on lt.pk = rt.fk

I've always been a little confused as to exactly which side the "left" side of the join is. The table on the left side of the "left join" keywords ... is that "the left table" or is the table on the left side of the on clause the left table as in the one that's on the left side of the equal sign. I've read articles that indicate that it's supposed to be

However ... now considering the following select statement ...

select  *
from    <some table> st
    inner join <left table> lt on st.pk = lt.fk
    left join <right table r on rt.fk = st.pk

In the above bit of code is the left table ? One would assume so considering the previous statments however because of the ambiguity or the unclarity (because it actually is not directly left) ... I would think that it would make more sense for the "left table" to be specified in the on clause.

So every bit of me seems to be fighting that logic ... and I need a little bit of clarification ... please and thanks.

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

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

发布评论

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

评论(2

辞取 2024-12-29 03:48:53

列出的第一个表是从中返回所有行的表。以 LEFT JOIN 命名的表将仅返回与第一个表匹配的行,并且在未找到匹配项的情况下返回 NULL 值。

The first table listed is the one from which all rows will be returned. The table that is named after the LEFT JOIN will return only rows which match the first table and will return NULL values where no match is found.

输什么也不输骨气 2024-12-29 03:48:53

一般来说 - 不,因为您又引入了一个过滤表。
但是 IF lt 的每一行在 st 中都有对应的且唯一 行 - 是的,行数将相同,列的集合将不同。但是第一个查询的结果集将是第二个查询的结果集的子集(仅在 st 表的列中存在差异)

In general - no, because you introduce one more filter table st.
But IF every row of lt has the corresponding and the only row in st - yes, the amount of rows will be the same, a collection of columns will differ. But the resultset from the first query will be a subset (difference only in columns from st table) of resultset from 2nd query

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