Subqueries
Subqueries
Queries
Objectives
Subquery:
SELECT select_list
FROM table
WHERE expr operator
(SELECT select_list
FROM table);
– Single-row subquery
Main query
returns
Subquery ST_CLERK
Main query
– Multiple-row subquery
returns
Subquery ST_CLERK
SA_MAN
Lesson Agenda
•Operat •Meaning
•
or = •Equal to
• > •Greater than
• >= •Greater than or
• < •equal
Less to
than
• <= •Less than or equal
• <> •toNot equal to
Executing Single-Row
Subqueries
…
What Is Wrong with This
Statement?
Single-row operator
with multiple-row
subquery
No Rows Returned by the
Inner Query
…
Using the ALL Operator
in Multiple-Row Subqueries
SELECT emp.last_name
FROM employees emp
WHERE emp.employee_id NOT IN
(SELECT mgr.manager_id
FROM employees mgr);
Summary
SELECT select_list
FROM table
WHERE expr operator
(SELECT select_list
FROM table);