mysql join 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.

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.

解决方案

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.

Right now I'm thinking a stand-alone JOIN is nothing more than (identical to) using commas and WHERE clauses.

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 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值