7. SELECT: ORDER BY

ORDER BY takes columns: a list of column names (or expressions), and you can add ASC (the default) or DESC (descending order):

SELECT TOP 5 source_id, parallax
FROM gaiadr1.tgas_source
ORDER BY parallax
SELECT TOP 5 source_id, parallax
FROM gaiadr1.tgas_source
ORDER BY parallax DESC
SELECT TOP 5 source_id, phot_g_mean_mag , parallax
FROM gaiadr1.tgas_source
ORDER BY phot_g_mean_mag, parallax

Note that ordering is outside of the relational model. That sometimes matters because it may mess up query planning (a rearrangement of relational expressions done by the database engine to make them run faster)

Problems

(1)

Select the source id and visual magnitude of the 20 brightest stars in the table tgas_source.


Markus Demleitner

Copyright Notice