Mysql 子查询还是联接?

Mysql 子查询还是联接?,mysql,sql,dbvisualizer,Mysql,Sql,Dbvisualizer,我正在使用subquery和join执行此语句: 显示财务部现有的所有职务(不要重复任何职务) 我的连接工作正常,我得到了正确的输出,但子查询没有,我看不到错误 输出告诉我: select DISTINCT(job_title) from jobs where job_id = (select job_id from employees where department_id = (select department_id

我正在使用subquery和join执行此语句: 显示财务部现有的所有职务(不要重复任何职务)

我的连接工作正常,我得到了正确的输出,但子查询没有,我看不到错误 输出告诉我:

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'


如果单独运行子查询,它应该显示多行


当你在做一个相等的(job_id=something)时,作为一个查询,该查询必须传递一个单一的值,结果不能隐式地出现在多行中。

如果不进行测试,你可能需要:

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'))

=
将一个值与一个值进行比较。子查询的结果可能是多个作业ID。因此,您不能使用
=
=以进行比较。您可以在
中使用
,但是现在可以使用,而不是
=
使用IN而不是=@patrickhornez是的,它现在可以工作了。谢谢,我没看见