SQL: Subquery reference
19 March 2023 (Updated 19 March 2023)
On this page
Example & execution plan
SELECT lastName, firstName FROM employees WHERE officeCode IN (SELECT officeCode FROM offices WHERE country = 'USA');
MySQL will execute the above query as follows:
- Execute the sub/inner query first to return the set of office codes in the US.
- Execute the outer query and feed the result of the subquery to the