对于 SQL,什么时候开始需要始终使用“Inner Join”一词?而不是隐式联合?

发布于 2024-08-30 07:38:44 字数 155 浏览 5 评论 0原文

对于 SQL,什么时候开始需要始终使用“Inner Join”一词而不是通过以下方式隐式连接:

select * from t1, t2 where t1.ID = t2.ID;

?仅仅是为了样式或区分外连接还是还有其他原因?

For SQL, when did it start to be desirable to always use the words "Inner Join" instead of implicitly joining by:

select * from t1, t2 where t1.ID = t2.ID;

? Is it just for style or to distinguish between outer join or are there other reasons for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

铁轨上的流浪者 2024-09-06 07:38:44

INNER 和 OUTER JOIN 语法在 SQL-92 规范中得到了形式化。在许多数据库产品(例如 MySQL 和 SQL Server)中,您可以省略内连接中的“INNER”一词,而仅使用“JOIN”。同样,许多数据库产品允许您省略“OUTER”一词,而仅使用“LEFT JOIN”或“RIGHT JOIN”进行外连接。旧的外连接语法 *==* 在许多情况下会产生歧义。许多产品已经或很快将停止支持旧的外连接语法。

在 SQL-92 规范之前,供应商各自使用自己的语法来表示外连接。即,*= 不是通用的(我似乎记得有人使用?=)。此外,他们没有以通用的方式实现外连接。举个例子:

Table1
Col1    Col2
1       Alice
2       Bob

Table2
Col1    Col2
1           1
2           2
3           3
4           4

Select 
From Table1, Table2
Where Table2.Col1 *= Table1.Col1

上面的查询通常会产生:

1   1   1       Alice
2   2   2       Bob
3   3   Null    Null
4   4   Null    Null

现在尝试:

Select 
From Table1, Table2
Where Table2.Col1 *= Table1.Col1
    And Table2.Name = 'Alice'

在某些数据库产品上,您会得到:

1   1   1       Alice

在其他数据库产品上,您会得到:

1   1   1       Alice
2   2   Null    Null
3   3   Null    Null
4   4   Null    Null

简而言之,对于是否应在或之前应用对未保留表的过滤是不明确的加入后。

The INNER and OUTER JOIN syntax was formalized in the SQL-92 specification. In many database products such as MySQL and SQL Server, you can omit the "INNER" word from inner joins and simply use "JOIN". Similarly, many database products let you omit the word "OUTER" and simply use "LEFT JOIN" or "RIGHT JOIN" for outer joins. The old outer join syntax of *= or =* created ambiguities in many circumstances. Many products have or very soon will stop supporting the old outer join syntax.

Prior to the SQL-92 specification, the vendors each used their own syntax indicated an outer join. I.e., *= was not universal (I seem to remember someone using ?=). In addition, they did not implement the outer join in a universal way. Take the following example:

Table1
Col1    Col2
1       Alice
2       Bob

Table2
Col1    Col2
1           1
2           2
3           3
4           4

Select 
From Table1, Table2
Where Table2.Col1 *= Table1.Col1

The above query would generally yield:

1   1   1       Alice
2   2   2       Bob
3   3   Null    Null
4   4   Null    Null

Now try:

Select 
From Table1, Table2
Where Table2.Col1 *= Table1.Col1
    And Table2.Name = 'Alice'

On some database products, you would get:

1   1   1       Alice

On others you would get:

1   1   1       Alice
2   2   Null    Null
3   3   Null    Null
4   4   Null    Null

In short, it is ambiguous as to whether the filtering on the unpreserved table should be applied before or after the join.

橙味迷妹 2024-09-06 07:38:44

当添加新语法来处理与外连接实现的不一致时,这就变得可取了。

由于使用旧语法组合外连接和内连接(以及特定的两个方向的外连接)在许多情况下是不明确的,因此必须创建和实现新语法,以允许程序员 100% 清楚连接的排序和分组条款。

然而,单独编写旧式内连接仍然是完全合法的,但旧式外连接正在以各种形式消失,很好的摆脱。

It became desirable when the new syntax was added to handle inconsistencies with outer join implementations.

Since combining outer and inner joins (and particular outer joins of both directions) with the old syntax is in many cases ambiguous, new syntax had to be created and implemented to allow the programmer to be 100% clear about the ordering and grouping of the join clauses.

It is, however, still perfectly legal to write the old-style inner joins by themselves, but the old-style outer joins are going away in all forms, and good riddance.

瞄了个咪的 2024-09-06 07:38:44

当它成为可能时,它就变得令人向往......

join 关键字更好地描述了“经典”连接的意图。此外,当查询中有多个联接时,要联接的表和要使用的条件会相邻出现,而不是将所有表放在一处,将所有条件放在另一处。

It became desirable when it became possible...

The join keyword better describes the intention that the "classical" join. Also, when you have many joins in a query, the table to join and the condition to use appear next to each other instead of having all tables in one place, and all the conditions in another.

尬尬 2024-09-06 07:38:44

我相信这是 ANSI 标准。当省略 ON 关键字时,它应该返回错误,并且 (IMO) 是一种更具声明性的风格。

I believe it is the ANSI standard. It should return an error when the ON keyword is omitted, and (IMO) is a more declarative style.

煞人兵器 2024-09-06 07:38:44

ansi-92 标准 嗯,这很难,我要冒险并猜测 1992 年

ansi-92 standard hmmm that's a hard one i'm gonna go out on a limb and guess 1992

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文