我有多个联接you can find it on sql fiddle的以下查询,这些查询无效DEF.ID
如何让以下联接从DEFINITION表中读取
SELECT *
FROM DEFINITION DEF
WHERE EXISTS (SELECT 1
FROM EMPLOYEE E
INNER JOIN MONTHLY_PAYMENT MP ON (MP.ID = E.CODE)
INNER JOIN DEPARTMENT DEP ON (DEP.ID = DEF.ID)
)
答案 0 :(得分:1)
根据Oracles规则,有两个问题,首先DEPARTMENT
需要与它所加入的两个表中的至少一个相关。第二,DEF
不能用作嵌套的内部条件连接,因此必须在WHERE
子句中使用。
SELECT DEF.ID
FROM DEFINITION DEF
WHERE EXISTS
(
SELECT 1 FROM EMPLOYEE E
INNER JOIN MONTHLY_PAYMENT MP ON (MP.ID=E.CODE)
INNER JOIN DEPARTMENT DEP ON DEP.ID=E.DEP_ID
WHERE DEP.ID=DEF.ID
)