FoDB - Lab 4- Subquery & Multiple Tables Query
FoDB - Lab 4- Subquery & Multiple Tables Query
&
Displaying Data from Multiple tables
Objectives
Main query:
Subquery:
SELECT select_list
FROM table
WHERE expr operator
(SELECT select_list
FROM table);
• Single-row subquery
Main query
returns
Subquery ST_CLERK
• Multiple-row subquery
Main query
returns ST_CLERK
Subquery
SA_MAN
Single-Row Subqueries
Operator Meaning
= Equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
<> Not equal to
Executing Single-Row Subqueries
…
What Is Wrong with This Statement?
Single-row operator
with multiple-row
subquery
Multiple-Row Subqueries
…
Using the ALL Operator
in Multiple-Row Subqueries
EMPLOYEES DEPARTMENTS
…
Creating Joins with the ON Clause
…
Creating Three-Way Joins with
the ON Clause
…
Applying Additional Conditions
to a Join
Use the AND clause or the WHERE clause to apply additional
conditions:
SELECT e.employee_id, e.last_name, e.department_id,
d.department_id, d.location_id
FROM employees e JOIN departments d
ON (e.department_id = d.department_id)
AND e.manager_id = 149 ;
Or
SELECT e.employee_id, e.last_name, e.department_id,
d.department_id, d.location_id
FROM employees e JOIN departments d
ON (e.department_id = d.department_id)
WHERE e.manager_id = 149 ;
Joining a Table to Itself
… …