本文介绍了在 SQL 中编写左/右 JOIN 时是否使用 OUTER 关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常看到有人这样写SQL:

I often see people who write SQL like this:

SELECT * from TableA LEFT OUTER JOIN TableB ON (ID1=I2)

我自己写的很简单:

SELECT * from TableA LEFT JOIN TableB ON (ID1=I2)

对我来说,OUTER"关键字就像线路噪音——它没有添加额外的信息,只是把 SQL 弄得一团糟.在我知道的大多数 RDBMS 中,它甚至是可选的.那么......为什么人们仍然写它?这是一种习惯吗?可移植性?(无论如何,您的 SQL 真的可移植吗?)还有什么我不知道的吗?

To me the "OUTER" keyword is like line noise - it adds no additional information, just clutters the SQL. It's even optional in most RDBMS that I know. So... why do people still write it? Is it a habit? Portability? (Are your SQL's really portable anyway?) Something else that I'm not aware of?

推荐答案

OUTER 在你写的时候真的是多余的,因为所有的 OUTER 连接要么是 LEFTRIGHT,反过来所有 LEFTRIGHT 连接都是 OUTER.所以从句法上讲,正如你所说的,它主要是噪音.即使在 ISO SQL 中它也是可选的.至于人们为什么使用它,我想有些人觉得有必要坚持连接是 OUTER,即使 left-or-right 关键字已经这么说了.就此而言,INNER 也是多余的!

OUTER really is superfluous, as you write, since all OUTER joins are either LEFT or RIGHT, and reciprocally all LEFT or RIGHT joins are OUTER. So syntactically it's mostly noise, as you put it. It is optional even in ISO SQL. As for why people use it, I suppose some feel the need the insist on the join being OUTER, even if the left-or-right keyword already says so. For that matter, INNER also is superfluous!

这篇关于在 SQL 中编写左/右 JOIN 时是否使用 OUTER 关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 04:53