Display the employee ID, LAST NAME, JOB_ID, Manager id for those employees who are in either the Sales or the Research department and a salary grade of C.
The answer was:
select empno, ename, job, mgr
from emp
where deptno IN (select deptno
from dept
where dname IN ('SALES', 'RESEARCH'))
and sal between(select losal from salgrade
where grade=3)
and (select hisal
from salgrade where
grade=3);
- Table EMP has columns EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO.
- Table SALGRADE has columns Grade, LoSal, HiSal.
- Table DEPT has columns DEPTNO, DNAME, LOC.
But I was wondering if there was a way to join these tables and display the answer because my first thought would be trying to INNER join these tables together.
I tried doing something like this:
select e.empno,e.ename,e.job,e.mgr
from emp e
join dept d on e.deptno = d.deptno
join salgrade s on e.sal between (
select losal
from salgrade
where grade =3)
and (
select hisal
from salgrade
where grade=3)
but couldn't find a way to include DNAME and I don't think the question asked for salary to be between losal and hisal.