6.13. SQL Select Order By

6.13.1. Order By

SELECT *
FROM astronauts
ORDER BY lastname;

6.13.2. Ascending

  • From smallest to biggest

  • ASC

SELECT *
FROM astronauts
ORDER BY lastname ASC;

6.13.3. Descending

  • From biggest to smallest

  • DESC

SELECT *
FROM astronauts
ORDER BY lastname DESC;

6.13.4. Multiple

  • When first criteria is the same

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

6.13.5. Empty

  • NULLS FIRST

  • NULLS LAST

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