使用带有 exists 运算符的 SQL 相关子查询

Using a SQL correlated sub-query with exists operator

我正在尝试查找 job_history table 中的所有记录,其 department_ID 与员工 table 中的 department_id 不同使用带有 exists 运算符的相关子查询,但是,我收到错误代码:

ORA-00933: SQL command not properly ended

有人可以根据下面的架构和代码告诉我我做错了什么吗?

Select * 
from Job_History as J 
where Exists(Select * from hr.Employees e where e.Department_ID != J.Department_ID);

这里:

from Job_History as J 

Oracle 不支持关键字 as 为 table 别名(仅在列别名中受支持)。

您很可能还希望在子查询的 employee_id 上有一个关联子句。

所以:

select * 
from job_history j 
where exists (
    select 1 
    from hr.employees e 
    where e.employee_id = j.employee_id and e.department_id <> j.department_id
);