Sub Queries
Sub queries is select statement that appears as part of another SQL
statement. Sub query is used when comparing data from different tables is
parenthesized whiting the where clause.
SELECT first_name, last_name FROM employees WHERE department_id = (SELECT department_id
FROM department WHERE section_id = 1112);
|
The above sample lists first name and last name of all the employees from
section 1112. You can tell that the section ID is not in the employee
table department ID is, and section ID is in the department table.
SELECT first_name, last_name FROM employee WHERE employee_id = (SELECT employee_id
FROM managers);
| This sub query lists employees whom exist both in the employees and managers tables
|