Subqueries:
*Subqueries in FROM clause
You can use subqueries to define a temporary table and use it in the FROM clause of an “outer” query.
SELECT * FROM (SELECT city, temp_hi - temp_lo AS temp_var FROM weather) AS w
WHERE temp_var > 20;
The above finds cities from the weather table whose daily temperature variation is greater than 20. The result is:
| city | temp_var | |—————– | ———| | ST LOUIS | 21 | | LOS ANGELES | 31 | | LOS ANGELES | 23 | | LOS ANGELES | 31 | | LOS ANGELES | 27 | | LOS ANGELES | 28 | | LOS ANGELES | 28 | | LOS ANGELES | 32 |
.