Chapter 7 Application Flashcards
Code a query with subquery to project employee data for all with salary less than the average salary for all employees.
Select * from employee where salary < (select avg(salary) from employee);
Prepare a nested query that projects employee name for all located in DALLAS (i.e. subquery to find, not “hard code”, the department number).
Select ename from employee where deptno = (select deptno from department where location = ‘DALLAS’);
Use the IN operator in a query with subquery to project department names for those departments with an employee earning more than $3000.
select dName, deptno from department where deptno IN (select deptno from employee where salary > 3000);
Use the ANY keyword in a query with subquery to show those departments with an employee earning less than $2000.*
select distinct(deptno) from employee where salary < ANY (select salary from employee where salary < 2000);
Prepare a correlated subquery to project employee name for all employees in that department located in DALLAS.
select ename from employee where deptno = (select deptno from department where location = ‘DALLAS’);
Do a correlated subquery with the EXISTS operator to list the names of departments that have employees.
select dName from department where deptno IN (select deptno from employee where ename IN (select ename from employee));
Do a correlated subquery with the NOT EXISTS operator to list the names of departments that do not have employees.
select dName from department where NOT EXISTS (select deptno from employee where deptno = department.deptno);
Prepare a nested query to project department name for the department having the lowest paid employee.
select dName from department where deptno = (select deptno from employee where salary = (select MIN(salary) from employee));