Difficulty: Beginner
Estimated time: 10–15 minutes
SQL concepts: LIMIT, controlling result size
Goal: Return only a specific number of rows from a query.
The Scenario
A product manager asks:
“Can you show me only the 3 cheapest products?”
When working with large datasets, you rarely want all rows.LIMIT lets you cap how many results are returned.
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 | Mechanical Keyboard | Accessories | 89.00 |
| 103 | 27-inch Monitor | Displays | 229.99 |
| 104 | USB-C Hub | Accessories | 34.50 |
| 105 | Laptop Stand | Workspace | 39.99 |
| 106 | Webcam | Accessories | 59.99 |
Your Task
Write a SQL query that returns:
nameprice
…but only the 3 cheapest products.
Expected Output
| name | price |
|---|---|
| Wireless Mouse | 24.99 |
| USB-C Hub | 34.50 |
| Laptop Stand | 39.99 |
Constraints
- Use
ORDER BY - Use
LIMIT - Do not use
SELECT *
Hint (Optional)
To get the cheapest items:
- Sort by price (ascending)
- Limit the number of rows returned
Order matters.
SELECT
name,
price
FROM products
ORDER BY price ASC
LIMIT 3;
Explanation
ORDER BY price ASCsorts from cheapest to most expensiveLIMIT 3returns only the first three rows- Without sorting first,
LIMITalone gives unpredictable results
Common Mistakes
- Using
LIMITwithoutORDER BY - Assuming LIMIT always returns the same rows
- Putting LIMIT before ORDER BY
Optional Extension (Mini Bonus)
Try:
- Show the 5 most expensive products
- Combine
LIMITwithWHERE - Add
OFFSETto skip rows
Next Challenge
Beginner Challenge #20: Skipping Rows with OFFSET
🔗 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.