TheAnalyst / SQLAll lessons ↗
Day 3 · Core SQL · 10–20 minutes

Sorting and limiting results

Use ORDER BY to sort and LIMIT to return only a few rows.

01 · Learn

The idea

Use ORDER BY to sort and LIMIT to return only a few rows. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.

SELECT order_id, amount FROM orders ORDER BY amount DESC, order_id ASC LIMIT 3;
Read it actively

Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.

02 · Recall

Explain it without looking

In your own words, explain the main SQL feature in today’s lesson and why it answers the question.

03 · Solve

Run your own query

Return the three largest orders, breaking ties by order_id ascending.

Loading browser SQL engine…
04 · Repeat

Close the loop