Summary: in this tutorial, we will show you how to use the MySQL subquery to write complex queries and explain the correlated subquery concept.
A MySQL subquery is a query that is nested inside another query such as SELECT, INSERT, UPDATE or DELETE. In addition, a MySQL subquery can be nested inside another subquery. A MySQL subquery is also called an inner query, while the query that contains the subquery is called an outer query.
Let’s take a look at the following subquery that returns employees who locate in the offices in the USA .
The subquery returns all offices codes of the offices that locate in the USA.
The outer query selects the last name and first name of employees whose office code is in the result set returned by the subquery.