SQL A 不是左连接 B,只是 A? [英] Isn't SQL A left join B, just A?

查看:26
本文介绍了SQL A 不是左连接 B,只是 A?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我查看了一些图表以了解连接之间的区别,然后我看到了这张图片:

So I was looking at a few graphs to understand the difference between the joins, and I came across this image:

也许问题在于用维恩图来表示这一点.但是看看左上角的第一个连接,基本上不是 A 吗?B 有什么不同?

Maybe the problem is in representing this with Venn Diagrams. But looking at the first join, top left, isn't that basically just A? What difference does B make there?

https://blog.jooq.org/2016/07/05/say-no-to-venn-diagrams-when-explaining-joins/

这个网站解释的很好

推荐答案

不,因为它是一个连接,它可以为 A 中的行产生大于 1 的基数.也就是说,如果有多个 匹配来自 B 的行,那么 A 中的一行将出现多次.

No, since it's a join, it can produce cardinalities greater than 1 for the rows in A. That is, if there are multiple matching rows from B then a row in A will show up multiple times.

示例:

表A:

id name
-- -------
 1 Alice
 2 Malcolm
 3 Kelly

表 B:

id_a preferred_food
---- --------------
   1 Pizza
   2 Burger
   2 Steak
   2 Menestroni

然后A left join B"会给你:

Then "A left join B" will give you:

id name    id_a preferred_food
-- ------- ---- --------------
 1 Alice      1 Pizza
 2 Malcolm    2 Burger
 2 Malcolm    2 Steak
 2 Malcolm    2 Menestroni
 3 Kelly   null null

简而言之:

  • A 中的所有行都出现在左连接中:甚至 3 Kelly 也出现了.
  • 当 B 中没有匹配的行时,B 中的列将显示为空值:行 3 Kelly 在最后两列中有 null.
  • 当 A 中的行在 B 中有多个匹配项时,它们可能会出现多次:行 2 Malcolm 出现了 3 次.
  • All rows from A show up in the left join: even 3 Kelly shows up.
  • Columns from B will show up with nulls when there are no matching rows in B: row 3 Kelly has null in the last two columns.
  • Rows in A may show up multiple times when they have multiple matches in B: row 2 Malcolm shows up three times.

这篇关于SQL A 不是左连接 B,只是 A?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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