什么是默认的 MySQL JOIN 行为,INNER 还是 OUTER? [英] What is the default MySQL JOIN behaviour, INNER or OUTER?

查看:126
本文介绍了什么是默认的 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 是可选的.INNERCROSS 在 MySQL 中是同义词.为清楚起见,如果我有连接条件,我会写 JOININNER 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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