Consider the following employees and departments tables from the sample
database
Suppose you have to find all employees who locate in the location
with the id 1700.
1. find all departments located at the location whose id is 1700:
SELECT * FROM departments WHERE location_id = 1700;
2. Second, find all employees that belong to the location 1700 by using
the department id list of the previous query:
SELECT employee_id, first_name, last_name FROM employees WHERE
department_id IN (1 , 3, 8, 10, 11)
SELECT employee_id, first_name, last_name FROM employees WHERE
department_id IN (SELECT department_id FROM departments WHERE
location_id = 1700) ORDER BY first_name , last_name;
finds employees whose salary is greater than the average salary of all
employees:
SELECT employee_id, first_name, last_name, salary FROM employees
WHERE salary > (SELECT AVG(salary)FROM employees);
SELECT first_name,last_name FROM employees UNION SELECT first_name,
last_name FROM dependents ORDER BY last_name;