在调试一些Oracle代码时,我遇到了以下查询:
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
我之前没有见过JOIN没有ON子句的。这行也令人困惑:
JOIN
ON
ON TPM_GROUP.GROUPID = TPM_GROUPTASKS.GROUPID
这似乎是一个ON没有任何匹配项的随机子句JOIN。查询运行时没有任何错误,并返回了一堆数据,因此很明显,语法是完全有效的。有人可以阐明这里到底发生了什么吗?
小宇宙…我昨天碰到了一个生成此语法的工具,颇为困惑。
显然,
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)