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?
基础教程推荐
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
