9.8. SQL Select Order By

9.8.1. Order By

SELECT *
FROM astronauts
ORDER BY lastname;

9.8.2. Ascending

  • From smallest to biggest

  • ASC

SELECT *
FROM astronauts
ORDER BY lastname ASC;

9.8.3. Descending

  • From biggest to smallest

  • DESC

SELECT *
FROM astronauts
ORDER BY lastname DESC;

9.8.4. Multiple

  • When first criteria is the same

SELECT *
FROM astronauts
ORDER BY lastname ASC, firstname DESC;

9.8.5. Empty

  • NULLS FIRST

  • NULLS LAST

SELECT *
FROM astronauts
ORDER BY mission NULLS FIRST;
SELECT *
FROM astronauts
ORDER BY mission ASC NULLS LAST;