Subqueries
In a SQL statement, a subquery operates like a joined table. It gathers data in a structured way and makes that data available for its outer SQL query. Placed in parentheses, a subquery, or an inner query, nests inside a parent, or an outer query. A subquery can nest in the following clauses of the parent query or another subquery:
SELECT
FROM
WHERE
A lot of the power of SQL products comes from their ability to link different tables in a single query. As we have seen already, we can link tables with inner and outer joins. In a query, we can also use a subquery to relate data from different tables. We can easily use the result of a subquery in the parent query without dealing with a join. Although queries with joins often have better performance, a subquery structure can seem a little more intuitive at first glance. Additionally, it's always good to have another option available when we build our queries. Both MySQL and SQL Server handle subqueries...