我正在使用subquery和join执行以下语句:
显示财务部门的所有职称(不重复任何职位)
我的Join工作正常,我得到了正确的输出,但是subquery没有,我看不到错误
输出给我这个:
select DISTINCT(job_title)
from jobs
where job_id = (select job_id from employees
where department_id =
(select department_id from departments
where department_name like 'finance'))
select DISTINCT(job_title) from jobs j
inner join employees e
on j.job_id = e.job_id
inner join departments d
on d.department_id = e.department_id
where department_name like 'finance'
最佳答案
如果不进行测试,您可能需要:
select DISTINCT(job_title)
from jobs
where job_id IN (select job_id from employees
where department_id IN
(select department_id from departments
where department_name like 'finance'))
关于mysql - 子查询还是联接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47517298/