Experiment of Database
Example 2 joins
4. List all departments that do not have any employees.
select deptno
from dept2016150071
where deptno not in (
select e.deptno from emp2016150071 e, dept2016150071 d
where e.deptno = d.deptno);
5 For each employee whose salary exceeds his manager’s salary, list the employee’s name and salary and the manager’s name and salary.
select e.ename, e.sal, m.ename, m.sal
from emp2016150071 e, emp2016150071 m
where e.mgr = m.empno and e.sal < m.sal
6 List the employees who have BLAKE as their manager.
select e.*, m.ename as Manager
from emp2016150071 e, emp2016150071 m
where e.mgr = m.empno and m.ename = 'BLAKE';
Exercise 6
1 List the name and job of employees who have the same job as Jones.
select ename, job from emp2016150071
where job in (select job from emp2016150071 where ename = 'JONES')
and ename != 'JONES'
2 Find all the employees in Department 10 that have a job that is the same as anyone in department 30.
select * from emp2016150071
where deptno = 10 and job in (
select job from emp2016150071 where deptno = 30)
3 List the name, job, and department of employees who have the same job as Jones or a salary greater than or equal to Ford.
select ename, job, deptno
from emp2016150071
where
job in (select job from emp2016150071 where ename = 'JONES')
or
sal in (select sal from emp2016150071 where sal > any (select sal from emp2016150071 where ename = 'FORD'))