Querydrill

Level 1: Basics Exercise 14 of 161 Easy Filter and sort

Skip rows with OFFSET

An SQL exercise from Querydrill. Solve it with a SQL editor in your browser, checked on the rows it returns and again on changed data, and it is checked the moment you submit.

Try it yourself

Sort the products by price, most expensive first. Return the name and price of the 4th, 5th and 6th product in that list, in that order.

products (8 rows)

idnamecategoryprice
1Desk LampHome35
2Office ChairHome180
3NotebookStationery4.5
4Pen SetStationery12
5HeadphonesElectronics95
6WebcamElectronics60
7MugHome9
8BackpackTravel70

Free, no account needed. PostgreSQL runs in your browser and your answer is checked again on changed data.

What this exercise teaches

LIMIT with OFFSET is how result pages are built: page 2 with 3 rows per page is LIMIT 3 OFFSET 3. It only makes sense together with ORDER BY, because without a sort the rows have no fixed order to skip through.

A hint if you get stuck

LIMIT sets how many rows come back, OFFSET how many are skipped first. To start at the 4th row, skip 3.

Background you need

Common mistakes on this exercise

  • Skips one row too many.
  • Sorted cheapest first.

Each of these returns a result that looks plausible. The checker catches them because it runs your query on changed data as well.

Keep going on the practice page

Your first 8 exercises on Querydrill are free, with no account. The practice page has the full editor, timed mode and all the exercises in order. A free account shows 3 reference solutions a day; Pro unlocks every exercise, every solution, timed mode and the certificate.

Open this exercise

More exercises in Basics