8.8. SQL Select Order By

8.8.1. Order By

SELECT *
FROM astronauts
ORDER BY lastname;

8.8.2. Ascending

  • From smallest to biggest

  • ASC

SELECT *
FROM astronauts
ORDER BY lastname ASC;

8.8.3. Descending

  • From biggest to smallest

  • DESC

SELECT *
FROM astronauts
ORDER BY lastname DESC;

8.8.4. Multiple

  • When first criteria is the same

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

8.8.5. Empty

  • NULLS FIRST

  • NULLS LAST

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