Blog · Guide

How SQL ORDER BY Works (Sort Your Results)

ORDER BY sorts the result ascending or descending — one column or several. Here’s the pattern you’ll reuse forever.

customers first_name last_name city result first_name · city
SELECT chooses which columns appear in the result.

A → Z and low → high by default

SELECT first_name, city
FROM customers
ORDER BY first_name;

Default is ASC (ascending). For expensive-first products use ORDER BY price DESC.

Sort by two columns

Need country, then city inside each country? List them in priority order:

ORDER BY country, city

First key wins; the second only breaks ties.

Try it yourself

The fastest way to lock this in is a short drill on the same Northstar Market tables.

Practice ORDER BY

Related guides