How do I get the top N rows by value with SQL?
SELECT customer, category, quantity * unit_price AS line_total
FROM data
ORDER BY line_total DESC
LIMIT 5;
Run this query in QueryLocal →
Combining `ORDER BY` with `LIMIT` gives you a top-N query: sort every row by the value you care about (here, each line's total), highest first, then cut the result off after the first 5 rows. This is the SQL way to answer 'what are my 5 biggest orders' without eyeballing a sorted spreadsheet column.
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).