你能有一个没有 ON 关键字的 INNER JOIN 吗?

2021-12-30 00:00:00 join sql oracle11g oracle

在调试一些 Oracle 代码时,我遇到了这个查询:

While debugging into some Oracle code, I came across this query:

SELECT TPM_TASK.TASKID FROM TPM_GROUP 
INNER JOIN TPM_USERGROUPS ON TPM_GROUP.GROUPID = TPM_USERGROUPS.GROUPID 
INNER JOIN TPM_TASK
INNER JOIN TPM_GROUPTASKS ON TPM_TASK.TASKID = TPM_GROUPTASKS.TASKID 
INNER JOIN TPM_PROJECTVERSION ON TPM_TASK.PROJECTID = TPM_PROJECTVERSION.PROJECTID AND TPM_TASK.VERSIONID = TPM_PROJECTVERSION.VERSIONID 
INNER JOIN TPM_TASKSTAGE ON TPM_TASK.STAGEID = TPM_TASKSTAGE.STAGEID 
INNER JOIN TPM_PROJECTSTAGE ON TPM_PROJECTVERSION.STAGEID = TPM_PROJECTSTAGE.STAGEID 
ON TPM_GROUP.GROUPID = TPM_GROUPTASKS.GROUPID

我被这条线搞糊涂了:

INNER JOIN TPM_TASK

我以前从未见过没有 ON 子句的 JOIN.同样令人困惑的是这条线:

I haven't seen a JOIN without an ON clause before. Also confusing is the line:

ON TPM_GROUP.GROUPID = TPM_GROUPTASKS.GROUPID

这似乎是一个随机的 ON 子句,没有任何匹配的 JOIN.查询运行没有任何错误,并返回一堆数据,很明显语法是完全有效的.有人能解释一下这里到底发生了什么吗?

This seems like a random ON clause without any matching JOIN. The query runs without any errors, and returns a bunch of data, so obvious the syntax is perfectly valid. Can someone shed some light on exactly what's going on here?

推荐答案

Small Universe... 昨天我遇到了一个生成这种语法的工具,很困惑.

Small universe... I ran across a tool generating this syntax yesterday and was rather flummoxed.

显然,

FROM a 
     INNER JOIN b
     INNER JOIN c ON (b.id = c.id)
     ON (a.id = c.id)

相当于嵌套子查询

FROM a
     INNER JOIN (SELECT <<list of columns>>
                   FROM b
                        INNER JOIN c ON (b.id=c.id)) c
             ON (a.id = c.id)

相关文章