>_ QueryLocal All recipes
SQL recipe

How do I sort by more than one column in SQL?

SELECT country, category, quantity * unit_price AS line_total
FROM data
ORDER BY country ASC, line_total DESC;
Run this query in QueryLocal →

`ORDER BY` accepts a comma-separated list of columns, each with its own direction (`ASC` or `DESC`, ascending by default). Rows are sorted by the first column, and only when two rows tie on that column does the second column break the tie — here, alphabetically by country, then by line total within each country.

A table named data with columns: order_id (integer), customer (text), country (text), category (text), quantity (integer), unit_price (real), order_date (text, YYYY-MM-DD).