1

I am using subquery and join to execute this statement: SHOW ALL THE JOB TITLES THAT EXIST IN FINANCE DEPARTMENT (DO NOT REPEAT ANY JOB TITLES)

my Join works and I get right output, but subquery doesn't and I can't see an error output gives me this :

error message

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'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
ANNA
  • 45
  • 5

2 Answers2

1

If you run the subquery alone it shold show you more than one row.

As you are doing an equal (job_id = something), that something, as it is a query, is has to deliver a single value as a result which implicitly can't come in more than one row).

Juan
  • 5,525
  • 2
  • 15
  • 26
1

Without testing, you probably want:

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'))
n8.
  • 1,732
  • 3
  • 16
  • 38