默认的 MySQL JOIN 行为是什么,INNER 还是 OUTER?
所以我在过去的一个小时里一直在浏览互联网,阅读并寻找这个简单问题的明确答案。
MySQL 中默认的 JOIN 是什么?
SELECT * FROM t1 JOIN t2
这与另一个相关问题相同吗
SELECT * FROM t1, t2
OR
SELECT * FROM t1 INNER JOIN t2
,当您使用“WHERE”子句时,它与 JOIN 或 INNER JOIN 相同吗?
现在我认为独立的 JOIN 与使用逗号和 WHERE 子句相同。
So I've been looking through the internet the last hour, reading and looking for the definitive answer to this simple question.
What is the default JOIN in MySQL?
SELECT * FROM t1 JOIN t2
Is that the same as
SELECT * FROM t1, t2
OR
SELECT * FROM t1 INNER JOIN t2
Also a related question, when you use "WHERE" clauses, is it the same as JOIN or INNER JOIN ?
Right now I'm thinking a stand-alone JOIN is identical to using commas and WHERE clauses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 MySQL 中,编写
JOIN
不合格意味着INNER JOIN
。换句话说,INNER JOIN
中的INNER
是可选的。INNER
和CROSS
在 MySQL 中是同义词。为了清楚起见,如果我有连接条件,我会写JOIN
或INNER JOIN
;如果我没有条件,我会写CROSS JOIN
。文档中描述了允许的连接语法。
效果是一样的,但背后的历史却不同。逗号语法来自 ANSI-89 标准。然而,这种语法存在许多问题,因此在 ANSI-92 标准中引入了 JOIN 关键字。
我强烈建议您始终使用 JOIN 语法而不是逗号。
T1 JOIN T2 ON ...
比T1, T2 WHERE ...
更具可读性。In MySQL writing
JOIN
unqualified impliesINNER JOIN
. In other words theINNER
inINNER JOIN
is optional.INNER
andCROSS
are synonyms in MySQL. For clarity I writeJOIN
orINNER JOIN
if I have a join condition andCROSS JOIN
if I don't have a condition.The allowed syntax for joins is described in the documentation.
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.
I would strongly recommend that you always use JOIN syntax rather than the comma.
T1 JOIN T2 ON ...
is more readable thanT1, T2 WHERE ...
.这些都是等价的,也等于
CROSS JOIN
。使用逗号和
[INNER | ] 之间存在一些差异。 CROSS] JOIN
语法,这在连接更多表时可能很重要。几乎所有您需要了解的内容都在 MySQLJOIN 中进行了描述
文档。These are all equivalent, and also equal to,
CROSS JOIN
.There are some differences between using comma and
[INNER | CROSS] JOIN
syntax, which might be important when joining more tables. Pretty much all you need to know is described here in the MySQLJOIN
documentation.