Difficulty: Beginner
Estimated time: 10–15 minutes
SQL concepts: ORDER BY, LIMIT, OFFSET
Goal: Skip a number of rows before returning results (pagination basics).
The Scenario
The product manager asks:
“Can you show me the next 3 cheapest products, skipping the cheapest ones we already saw?”
This is a common requirement for pagination—showing results page by page.
Database Table
products
| column_name | type | description |
|---|---|---|
| product_id | INTEGER | Unique product ID |
| name | TEXT | Product name |
| category | TEXT | Product category |
| price | DECIMAL | Product price |
Sample Data
| product_id | name | category | price |
|---|---|---|---|
| 101 | Wireless Mouse | Accessories | 24.99 |
| 102 | USB-C Hub | Accessories | 34.50 |
| 103 | Laptop Stand | Workspace | 39.99 |
| 104 | Webcam | Accessories | 59.99 |
| 105 | Mechanical Keyboard | Accessories | 89.00 |
| 106 | 27-inch Monitor | Displays | 229.99 |
Your Task
Write a SQL query that returns:
nameprice
…but skips the 3 cheapest products and returns the next 3 cheapest.
Expected Output
| name | price |
|---|---|
| Webcam | 59.99 |
| Mechanical Keyboard | 89.00 |
| 27-inch Monitor | 229.99 |
Constraints
- Use
ORDER BY - Use
LIMIT - Use
OFFSET - Do not use
SELECT *
Hint (Optional)
To get predictable results:
- Sort the data first
- Skip rows with
OFFSET - Limit how many rows are returned
Order matters.
SELECT
name,
price
FROM products
ORDER BY price ASC
LIMIT 3
OFFSET 3;
Explanation
ORDER BY price ASCsorts products from cheapest to most expensiveOFFSET 3skips the first three rowsLIMIT 3returns the next three rows after the skipped ones
Together, LIMIT + OFFSET form the foundation of pagination.
Common Mistakes
- Using
OFFSETwithoutORDER BY - Forgetting that row order is undefined without sorting
- Mixing up
LIMITandOFFSETvalues
Optional Extension (Mini Bonus)
Try:
- Skip the first 5 products and show the next 2
- Combine
OFFSETwith aWHEREclause - Implement page-based logic (page × page size)
Next Challenge
Beginner Challenge #21: Pagination Patterns (LIMIT vs OFFSET vs Cursor)
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.