为什么在 MySQl 中有左连接和右连接? [英] why there is a left join and right join in MySQl?

查看:52
本文介绍了为什么在 MySQl 中有左连接和右连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为左/右联接就足够了,如果交换表名,另一个将派生出来,有人知道为什么同时存在左联接和右联接吗?谢谢

I think either left/right join is sufficient, the other will derived if table names are interchanged, Anyone know why there is both left and right join? Thanks

推荐答案

join 求值的顺序一般是从左到右.所以 a join b join c 的执行就像你把它放在括号里 (a join b) join c 一样.

The order of join evaluation is generally left-to-right. So a join b join c executes as if you had parenthesized it (a join b) join c.

优化器可以对内连接重新排序,因为内连接是可交换的.重新排序外连接不是可交换的(即 a left join bb left join a 不同),因此优化器不能交换它们.

The optimizer can reorder inner joins because inner joins are commutative. Reordering outer joins is not commutative (i.e. a left join b is not the same as b left join a), so the optimizer can't swap them.

如果要对连接的一对表的结果进行左外连接,请使用括号,例如:a left join (b join c).

If you want to do a left outer join to the result of a joined pair of tables, use parentheses, like: a left join (b join c).

但是您也可以通过切换到右外连接来利用从左到右的求值顺序:b join c 右外连接 a -- 不带括号!

But you can also take advantage of the left-to-right order of evaluation by switching to a right outer join: b join c right outer join a -- without parentheses!

这篇关于为什么在 MySQl 中有左连接和右连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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