Brightlane's inventory team is processing the product catalogue alphabetically and has already handled the first 5 products. They want a list of every remaining product so they can continue from where they left off.
Write a query to return the ID and name of every product after the first 5.
Assumptions:
- The
productstable contains every product in Brightlane's catalogue. OFFSETwithout aLIMITis valid — PostgreSQL skips the specified number of rows and returns every row after that.
Output:
- One row per remaining product, with columns
idandname, sorted bynameascending.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
id,
name
FROM
products
ORDER BY
name
OFFSET
5 The shape
OFFSET 5 without a paired LIMIT skips the first five alphabetical products and returns every row after — the rest of the catalogue from row 6 onward.
Clause by clause
SELECT id, namepicks the two columns the inventory team needs to continue their walk through the catalogue.FROM productsreads the full catalogue.ORDER BY namesorts alphabetically — the same order the team has been processing the catalogue in. Without the same sort, "the first 5 we already handled" and "the rows we skip" wouldn't line up.OFFSET 5discards the first five rows of the sorted result. Coffee Table atid25 lands as the first row returned because it sits at position 6 in the alphabetical sort.
Why no LIMIT
LIMIT and OFFSET are independent controls. LIMIT caps the back of the result; OFFSET trims the front. Either can appear without the other. Here the team wants everything past the first five rows, with no cap on how many products come back — so OFFSET appears alone. PostgreSQL skips the first five rows and then keeps returning rows until the result set is exhausted, which leaves 58 products in this catalogue.
The two clauses can also appear in the other arrangement. LIMIT 5 alone returns just the first five products — the rows the team has already handled. Together, LIMIT 5 OFFSET 5 would return rows 6 through 10 as a single page. The same two controls compose into top-N, bottom-N, paginated windows, and tail-of-the-list queries depending on which is present and how they're sized.
You practiced using OFFSET without a LIMIT to return everything past a starting point. The two clauses are independent controls — OFFSET alone trims the front of the result, LIMIT alone trims the back, together they carve out a window.