存在无效标识符

时间:2018-04-10 16:10:12

标签: sql oracle

我有多个联接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)
             )

1 个答案:

答案 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
 )