SolveWithSQL

SQL Beginner Challenge 20: Skipping Rows with OFFSET

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_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price

Sample Data

product_idnamecategoryprice
101Wireless MouseAccessories24.99
102USB-C HubAccessories34.50
103Laptop StandWorkspace39.99
104WebcamAccessories59.99
105Mechanical KeyboardAccessories89.00
10627-inch MonitorDisplays229.99

Your Task

Write a SQL query that returns:

  • name
  • price

…but skips the 3 cheapest products and returns the next 3 cheapest.

Expected Output

nameprice
Webcam59.99
Mechanical Keyboard89.00
27-inch Monitor229.99

Constraints

  • Use ORDER BY
  • Use LIMIT
  • Use OFFSET
  • Do not use SELECT *

Hint (Optional)

To get predictable results:

  1. Sort the data first
  2. Skip rows with OFFSET
  3. 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 ASC sorts products from cheapest to most expensive
  • OFFSET 3 skips the first three rows
  • LIMIT 3 returns the next three rows after the skipped ones

Together, LIMIT + OFFSET form the foundation of pagination.

Common Mistakes

  • Using OFFSET without ORDER BY
  • Forgetting that row order is undefined without sorting
  • Mixing up LIMIT and OFFSET values

Optional Extension (Mini Bonus)

Try:

  1. Skip the first 5 products and show the next 2
  2. Combine OFFSET with a WHERE clause
  3. 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.