SQL: Subquery reference
19 March 2023 (Updated 22 October 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
WHERE
clause.
Sources
Tagged:
MySQL
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment