SELECT .. SELECT
Subquery Table, Derived Tables, Nested Queries
You can use the results from one query in another query
You may use a SELECT statement in the FROM line SELECT f FROM (SELECT ).
In this case the derived table X has columns
The calculated values in the inner SELECT can be used in the outer SELECT.
SELECT name, ROUND(gdp_per_capita) FROM (SELECT name, gdp/population AS gdp_per_capita FROM bbc) X WHERE region='North America'
- the inner table is given an alias X
- the first column in the inner query keeps its name
- the second column in the inner query has an alias