Top N and Paging
The newest, the next three.
Two everyday questions now. Who are my three newest customers? And, show me the next three after that. These are top N, and paging, and you'll see them everywhere, from leaderboards to search results.

- Who joined most recently?
- Show the next page
- Leaderboards and search results
The newest customers
The joined column holds the date each customer signed up. Sorting by it, newest first, then limiting to three, gives the newest customers. Run it. Lina Dubois joined most recently, in June twenty twenty five.
SELECT first_name, last_name, joined
FROM customers
ORDER BY joined DESC
LIMIT 3;โโโโโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโโ โ first_name โ last_name โ joined โ โโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโค โ Lina โ Dubois โ 2025-06-19 โ โ Will โ Haddad โ 2025-06-15 โ โ Gita โ Brown โ 2025-06-12 โ โโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโ
The next page
Offset skips some rows before limit starts counting. Limit three, offset three, skips the top three, then takes the next three. That's page two. Run it. These are the fourth, fifth, and sixth most expensive books.
SELECT title, price
FROM books
ORDER BY price DESC
LIMIT 3 OFFSET 3;โโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโ โ title โ price โ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโค โ Spice Roads โ 27.99 โ โ The Quiet Kitchen โ 24.99 โ โ The Pricing Game โ 23.99 โ โโโโโโโโโโโโโโโโโโโโโดโโโโโโโโ
Running low
Your turn. Helen worries about books running out. Show the title and stock of the three books with the lowest stock. Pause and try. Here's a solution. Order by stock, smallest first, limit three. The Quiet Kitchen is completely sold out.
Show the 3 books with the lowest stock
Show hint
ORDER BY stock, then LIMIT
Show solution
SELECT title, stock
FROM books
ORDER BY stock
LIMIT 3;โโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโ โ title โ stock โ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโค โ The Quiet Kitchen โ 0 โ โ Spice Roads โ 2 โ โ Data for Everyone โ 3 โ โโโโโโโโโโโโโโโโโโโโโดโโโโโโโโ
Summary
Order by and limit give you a top N. Offset gives you the next page. You've finished the first module. Next, we'll make new columns with calculations.
Key takeaways- ORDER BY + LIMIT = top N
- OFFSET skips rows
- Page two: LIMIT 3 OFFSET 3