14. Subqueries

One of the more powerful features of SQL is that you can have subqueries instead of tables within FROM. Just put them in parentheses and give them a name using AS. This is particularly convenient when you first want to try some query on a subset of a big table:

SELECT count(*) as n, round((hmag-jmag)*2) as bin
FROM (
  SELECT TOP 4000 * FROM twomass) AS q
GROUP BY bin
ORDER BY bin


Markus Demleitner

Copyright Notice