Question

The following is the prompt i'm trying to answer:

Write the nested statement to list the first and last names of those employees who have the same job as Larry Smith.

The following is the employee table columns:

EMPLOYEE(Emp_Num, Emp_Lname, Emp_Fname,Emp_Initial, Emp_HireDate, Job_Code)

The following is my nested query:

select emp_fname, emp_lname
from EMPLOYEE
where job_code =
(select job_code
from employee
where emp_fname = 'larry'
and emp_lname = 'smith');

Why is this not working?

Was it helpful?

Solution

You should be using IN not =:

select emp_fname, emp_lname
from EMPLOYEE
where job_code IN
  (select job_code
   from employee
   where emp_fname = 'larry'
     and emp_lname = 'smith');

The reason being that you are comparing a value to the set returned by the subquery.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top