0PricingLogin
SQL Academy · Lesson

ORDER BY Single and Multiple Columns

Sort results ascending or descending, sort by multiple columns, and control where NULLs land with NULLS FIRST / NULLS LAST.

Why You Need ORDER BY

A SQL table is an unordered set. Without ORDER BY, the database may return rows in any order — and that order can change between runs. If order matters in your UI or report, sort explicitly.

Sorting by One Column

Default sort is ascending:

SELECT id, email FROM users ORDER BY created_at;       -- oldest first
SELECT id, email FROM users ORDER BY created_at ASC;
SELECT id, email FROM users ORDER BY created_at DESC;  -- newest first

All lessons in this course

  1. Selecting Columns and Expressions
  2. WHERE Filters: Comparison and Logic Operators
  3. ORDER BY Single and Multiple Columns
  4. LIMIT, OFFSET and Pagination Basics
← Back to SQL Academy