>_ QueryLocal All recipes
SQL recipe

How do I sort by customer and then by value (ASC) in SQL?

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

Multi-column `ORDER BY` sorts first by customer (ASC), and only breaks ties on that column using `line_total DESC` as the second key — the same tie-breaking logic as sorting a spreadsheet by two columns at once.

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).