MySQL 左外连接和左连接一样吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15425740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:55:53  来源:igfitidea点击:

Are left outer joins and left joins the same?

mysqlsql

提问by PSR

I have seen joins called LEFT OUTER JOIN or RIGHT OUTER JOIN. In some places I have seen LEFT JOIN or RIGHT JOIN. I am confused by this.

我见过称为 LEFT OUTER JOIN 或 RIGHT OUTER JOIN 的连接。在某些地方,我见过 LEFT JOIN 或 RIGHT JOIN。我对此感到困惑。

I posted a question 2 days ago, but I am unable to understand the links the solutions provide.

我2 天前发布了一个问题,但我无法理解解决方案提供的链接。

Are these types of joins both the same, or is there some difference between the two?

这些类型的连接是否相同,或者两者之间有什么区别?

回答by divyabharathi

There are no difference between both. Refer visual represenation of joins

两者没有区别。参考联接的视觉表示

回答by Udo Klein

The first link they quoted gives you:

他们引用的第一个链接为您提供:

INNER JOIN: returns rows when there is a match in both tables.

INNER JOIN: 当两个表中存在匹配时返回行。

LEFT JOIN / LEFT OUTER JOIN: returns all rows from the left table, even if there are no matches in the right table.

LEFT JOIN / LEFT OUTER JOIN: 返回左表中的所有行,即使右表中没有匹配项。

RIGHT JOIN / RIGHT OUTER JOIN: returns all rows from the right table, even if there are no matches in the left table.

RIGHT JOIN / RIGHT OUTER JOIN: 返回右表中的所有行,即使左表中没有匹配项。

FULL JOIN / FULL OUTER JOIN / OUTER JOIN: returns rows when there is a match in one of the tables.

FULL JOIN / FULL OUTER JOIN / OUTER JOIN: 当其中一个表中有匹配项时返回行。

SELF JOIN: is used to join a table to itself, as if the table were two tables, temporarily renaming at least one table in the SQL statement.

SELF JOIN: 用于将一个表连接到自身,就好像该表是两个表,在SQL语句中临时重命名至少一个表。

CARTESIAN JOIN: returns the cartesian product of the sets of records from the two or more joined tables.

CARTESIAN JOIN: 返回两个或多个连接表中记录集的笛卡尔积。

The self joinis actually not a special join. It just reflects the fact that you can join a table with itself. Doing so you must alias it in order to address the fact that it appears more than once in the same statement.

self join实际上不是special join。它只是反映了一个事实,即您可以将表与自身连接。这样做时,您必须为它设置别名,以解决它在同一语句中多次出现的事实。

The cartesian joincan be considered as an inner joinwithout a restricting condition. Or you may view an inner joinas a cartesian joinwith an added restriction (the join condition).

cartesian join可以被认为是inner join没有限制的条件。或者您可以将 ainner join视为cartesian join具有附加限制(连接条件)。

回答by Ed Heal

If you look at the manual page for JOINyou will see the following lines:

如果您查看JOIN的手册页,您将看到以下几行:

join_table:

   table_reference [INNER | CROSS] JOIN table_factor [join_condition]

   | table_reference STRAIGHT_JOIN table_factor

   | table_reference STRAIGHT_JOIN table_factor ON conditional_expr

| table_reference {LEFT|RIGHT} [OUTER] JOIN table_reference join_condition

| table_reference {LEFT|RIGHT} [OUTER] JOIN table_reference join_condition

   | table_reference NATURAL [{LEFT|RIGHT} [OUTER]] JOIN table_factor

The bold line clearly shows that the keyword OUTER is optional.

粗线清楚地表明关键字 OUTER 是可选的。

回答by Explosion Pills

In MySQL syntax, LEFT OUTER JOINand LEFT JOINare identical: (from http://dev.mysql.com/doc/refman/5.0/en/join.html)

在 MySQL 语法中,LEFT OUTER JOIN并且LEFT JOIN是相同的:(来自http://dev.mysql.com/doc/refman/5.0/en/join.html

| table_reference {LEFT|RIGHT} [OUTER] JOIN table_reference join_condition
| table_reference NATURAL [{LEFT|RIGHT} [OUTER]] JOIN table_factor

Note that the OUTERkeyword is optional for LEFT/RIGHT JOIN.

请注意,该OUTER关键字对于 LEFT/RIGHT JOIN 是可选的。

LEFT and RIGHT joins are both outer joins. I believe there are some flavors of SQL that may require the OUTERkeyword, but MySQL does not. That is to say that at times LEFT JOINmay not be valid.

LEFT 和 RIGHT 连接都是外部连接。我相信有些风格的 SQL 可能需要OUTER关键字,但 MySQL 不需要。也就是说,有时LEFT JOIN可能无效。

回答by Sadia Aziz

I am working in SQL Server and as per my usage and experience there is absolutely no difference between LEFT JOINand LEFT OUTER JOIN. The same is true for RIGHT JOINand RIGHT OUTER JOIN. When you use LEFT JOINkeyword in SQL Server, it means LEFT OUTER JOINonly. So as per my opinion its the generic rule which is same for all database engines.

我在 SQL Server 中工作,根据我的使用和经验,LEFT JOINLEFT OUTER JOIN. RIGHT JOIN和也是如此RIGHT OUTER JOIN。当您LEFT JOIN在 SQL Server 中使用关键字时,它的意思是LEFT OUTER JOINonly。所以根据我的观点,它的通用规则对于所有数据库引擎都是相同的。

see hereand here

看到这里这里