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

查看:1351
本文介绍了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子句写在joins的旁边,很容易看出是否缺少.
  • T1 JOIN T2 ON ... is more readable than T1, T2 WHERE ....
  • It is more maintainable because the table relationships and filters are clearly defined rather than mixed together.
  • The JOIN syntax is easier to convert to OUTER JOIN than the comma syntax.
  • Mixing the comma and JOIN syntax in the same statement can give curious errors due to the precedence rules.
  • It is less likely to accidentally create a cartesian product when using the JOIN syntax due to a forgotten join clause, because the join clauses are written next to the joins and it is easy to see if one is missing.

这篇关于MySQL JOIN的默认默认行为是INNER或OUTER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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