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

查看:72
本文介绍了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/

这个网站很好地解释了

推荐答案

不,这是一个联接.如果B中有多个 matching 行,则A中的一行将显示多次.

No, it's a join. 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左连接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行中会出现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's 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 shows up three times.

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

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