- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我一直在尝试完全理解 sql 连接的概念,维恩图在这方面帮助了我很多。我发现它们适用于所有类型的连接,但不适用于自然连接。
自然连接的维恩图会是什么样子?
最佳答案
维恩图对于理解自然连接或内部连接不是很有帮助。大多数与 Stack Overflow 和网络上的连接相关的维恩图都是重复的毫无值(value)的虚假陈述——即使在维恩图可能有用的情况下也是如此。
以下是维恩图在 SQL 自然连接中的一些有效用法:
我们可以让一个区域成为一个集合,其元素是关联表的列名。那么左右circle元素就是左右表的列名,overlap元素就是公共(public)的列名(每个输入表中必须出现一次),合并的元素就是结果的列名。但是 SQL 表可以有重复的列名,并且列是有序的;所以这不会给出结果列列表。
我们可以让一个区域成为一个集合,其元素是公共(public)列下的不同子行值。那么左右circle元素就是左右表子行值,overlap元素就是结果子行值。但这并没有给出子行值在表中出现的次数。特别是,当所有列都通用时,子行值就是行值,这不会给出行值在结果中出现的次数。
图表和配对都没有给出输出行的一般情况。
来自 my answer在CROSS JOIN vs INNER JOIN in SQL :
Re Venn diagrams A Venn diagram with two intersecting circles can illustrate the difference between output rows for INNER, LEFT, RIGHT & FULL JOINs for the same input. And when the ON is unconditionally TRUE, the INNER JOIN result is the same as CROSS JOIN. Also it can illustrate the input & output rows for INTERSECT, UNION & EXCEPT. And when both inputs have the same columns, the INTERSECT result is the same as for standard SQL NATURAL JOIN, and the EXCEPT result is the same as for certain idioms involving LEFT & RIGHT JOIN. But it does not illustrate how (INNER) JOIN works in general. That just seems plausible at first glance. It can identify parts of input and/or output for special cases of ON, PKs (primary keys), FKs (foreign keys) and/or SELECT. All you have to do to see this is to identify what exactly are the elements of the sets represented by the circles. (Which muddled presentations never make clear.) (Remember that in general for joins output rows have different headings from input rows.)
我再次强调:
But it does not illustrate how (INNER) JOIN works in general.
All you have to do to see this is to identify what exactly are the elements of the sets represented by the circles.
来自 one of my comments在一个答案中有内部连接的维恩图:
Figure 1 is a common terrible attempt to explain JOIN. Its [legend] is also complex: It's only for tables as sets & only equijoin & only one [column]; it also represents the input differently than the output. Write it for JOIN in general.
来自 one of my comments在 What is the difference between "INNER JOIN" and "OUTER JOIN"? :
Venn diagrams show elements in sets. Just try to identify exactly what the sets are and what the elements are in these diagrams. The sets aren't the tables and the elements aren't their rows. Also any two tables can be joined, so PKs & FKs are irrelvant. All bogus. You are doing just what thousands of others have done--got a vague impression you (wrongly) assume makes sense.
和another :
Of the answers & comments & their references below only one actually explains how Venn diagrams represent the operators: The circle intersection area represents the set of rows in A JOIN B. The area unique to each circle represents the set of rows you get by taking its table's rows that don't participate in A JOIN B and adding the columns unique to the other table all set to NULL. (And most give a vague bogus correspondence of the circles to A and B.)
因此维恩图与某些情况相关在这些情况下可以合理地认为表格包含行值元素集。 但一般而言,SQL 表不包含行值元素的集合,而维恩图表示集合。
通过维恩图重新说明内部连接与外部连接:
来 self 对 LEFT JOIN vs. LEFT OUTER JOIN in SQL Server 的评论:
Re Venn diagrams: If no nulls or duplicate rows are input, so we can take a table to be a set of row-valued values & use normal math =, then the Venn diagrams are OK--taking circles to hold left & right join output tables/sets. But if nulls or duplicate rows are input then it is so difficult to explain just what the circles are sets of & how those sets relate to input & output tables/bags that Venn diagrams are not helpful.
来自 my comment on my answer至 What is the difference between "INNER JOIN" and "OUTER JOIN"? :
I must admit that, despite my quick phrasing in comments, because SQL involves bags & nulls and SQL culture doesn't have common terminology to name & distinguish between relevant notions, it is non-trivial even to explain clearly how elements of a Venn diagram are 1:1 with output "rows", let alone input "rows". Or what inner or outer joins do, let alone their difference. "value" may or may not include NULL, "row" may be a list of values vs a slot in a table value or variable & "=" may be SQL "=" vs equality.
PS 通常图表称为 Venn diagrams当他们真的是Euler diagrams .
关于sql - 自然连接的维恩图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55639641/
我有一套使用两种语言的文档:英语和德语。关于这些文档没有可用的元信息,程序只能查看其内容。基于此,程序必须决定用哪种语言编写文档。 是否有可以在几个小时内实现的针对该问题的“标准”算法?或者,一个免费
背景 我有一个日志系统,可以将记录输出到 std::ostream .每条记录都用一个计数器进行注释,该计数器随着每个输出而增加 1,如下所示: ===== Batch # 5 ===== T
用户可能希望根据需要分隔数字。 从字符串中提取所有(自然)数字的最有效(或简单的标准函数)是什么? 最佳答案 您可以使用正则表达式。我从 Sun's regex matcher tutorial 修改
我认为如果表有代理键而没有(自然)替代键是没有意义的(请记住,代理键的属性之一是它在数据库之外没有意义环境)。 例如假设我有下表: 假设 employee_id 是代理主键,表中没有(自然)备用键。
我想将屏幕方向锁定为其默认方向。我在实现这一点时遇到问题。最初我将屏幕锁定为 list 中的肖像。它适用于纵向默认设备。但是许多平板电脑默认为横向,因此在这些设备中锁定纵向是不合适的,我想检测此默认方
我已将笔记本电脑上的触摸板滚动设置为倒置(自然)。它适用于任何地方(pdf、浏览器等),但在 vscode 中,它坚持正常滚动。通过 vscode 的设置文件没有显示适当的条目。 系统:Ubuntu
在我发现的许多在上限集合上使用可尾游标的示例中,代码包括: hint( { $natural: 1 } ) (例如 here ),包括官方文档 ( here ),以“确保我们不使用任何索引”,并且结果
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: T
一些上下文:Node.js、Bot、natural module . 我想构建一个机器人,并且我正在使用自然模块来解析用户输入并对其进行总体分类。 var classifier = new natur
我是一名优秀的程序员,十分优秀!