2010-10-05 38 views
1

我有一些旧的代码我经历了,我只是发现有两个“开”条款一加入...奇怪的联接语法在传统的SQL代码

select * from table 
inner join table3 
inner join table2 on table3.key = table2.fkey on table.key = table2.otherkey 

什么这种连接的平均? (它当前工作,所以它不是一个语法错误)

(编辑:固定的代码,缺少一个连接)

+0

你确定吗?我无法得到这样的声明编译 – AakashM 2010-10-05 07:45:27

+0

对不起,错过了对奇怪加入至关重要的连接:)编辑原始帖子... – 2010-10-05 07:46:09

+0

SQL有什么特色? – MikeAinOz 2010-10-05 07:46:39

回答

4

发表您的编辑它只是知道隐含的优先级的情况。

select * from table1 
inner join table3 
inner join table2 on table3.key = table2.fkey on table1.key = table2.otherkey 

相同

select * from 
table1 inner join 
    (table3 inner join table2 on table3.key = table2.fkey) 
on table1.key = table2.otherkey 

其中希望更有意义。我在这里所做的只是添加括号。

第一次加入,table3table2,从概念上讲,会生成一个中间表,其中包含所有列。然后使用您看到的第二个on子句将table1加入到此。

+0

啊,是的......这是有道理的,但使得阅读代码糟透了: – 2010-10-05 07:59:34