What is the default MySQL JOIN behaviour, INNER or OUTER?(什么是默认的 MySQL JOIN 行为,INNER 还是 OUTER?)
问题描述
所以我过去一个小时一直在浏览互联网,阅读并寻找这个简单问题的最终答案.
So I've been looking through the internet the last hour, reading and looking for the definitive answer to this simple question.
MySQL 中的默认 JOIN 是什么?
What is the default JOIN in MySQL?
SELECT * FROM t1 JOIN t2
是不是一样的
SELECT * FROM t1, t2
OR
SELECT * FROM t1 INNER JOIN t2
还有一个相关的问题,当你使用WHERE"子句时,它和 JOIN 或 INNER JOIN 一样吗?
Also a related question, when you use "WHERE" clauses, is it the same as JOIN or INNER JOIN ?
现在我认为独立的 JOIN 与使用逗号和 WHERE 子句相同.
Right now I'm thinking a stand-alone JOIN is identical to using commas and WHERE clauses.
推荐答案
在 MySQL 中编写 JOIN
不合格意味着 INNER JOIN
.换句话说,INNER JOIN
中的 INNER
是可选的.INNER
和 CROSS
在 MySQL 中是同义词.为清楚起见,如果我有连接条件,我会写 JOIN
或 INNER JOIN
,如果我没有条件,我会写 CROSS JOIN
.
In MySQL writing JOIN
unqualified implies INNER JOIN
. In other words the INNER
in INNER JOIN
is optional. INNER
and CROSS
are synonyms in MySQL. For clarity I write JOIN
or INNER JOIN
if I have a join condition and CROSS JOIN
if I don't have a condition.
允许的连接语法在文档中描述.
The allowed syntax for joins is described in the documentation.
现在我认为独立的 JOIN 无非是(等同于)使用逗号和 WHERE 子句.
Right now I'm thinking a stand-alone JOIN is nothing more than (identical to) using commas and WHERE clauses.
<小时>
效果是一样的,但背后的历史却不同.逗号语法来自 ANSI-89 标准.然而,这种语法存在许多问题,因此在 ANSI-92 标准中引入了 JOIN 关键字.
The effect is the same, but the history behind them is different. The comma syntax is from the ANSI-89 standard. However there are a number of problems with this syntax so in the ANSI-92 standard the JOIN keyword was introduced.
我强烈建议您始终使用 JOIN 语法而不是逗号.
I would strongly recommend that you always use JOIN syntax rather than the comma.
T1 JOIN T2 ON ...
比T1, T2 WHERE ...
更具可读性.- 它更易于维护,因为表关系和过滤器被明确定义而不是混合在一起.
- JOIN 语法比逗号语法更容易转换为 OUTER JOIN.
- 在同一语句中混合使用逗号和 JOIN 语法可能会由于优先级规则而产生奇怪的错误.
- 在使用 JOIN 语法时由于忘记了 join 子句而意外创建笛卡尔积的可能性较小,因为 join 子句写在连接旁边,很容易看出是否缺少一个.
这篇关于什么是默认的 MySQL JOIN 行为,INNER 还是 OUTER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么是默认的 MySQL JOIN 行为,INNER 还是 OUTER?


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01