N008-H1 Tier 1 · Foundations · hard ecommerce · Brightlane

Return the ID, name, and price for every product in that batch

Part of LIMIT and OFFSET in SQL

The problem

Brightlane's product export tool pages through the catalogue in alphabetical batches of 10. The tool is requesting the batch that starts at position 61.

Write a query to return the ID, name, and price for every product in that batch.

Assumptions:

  • The products table contains exactly 63 products in Brightlane's catalogue.
  • The batch starts at position 61, so 60 rows must be skipped — OFFSET 60, then LIMIT 10.
  • Only 3 products remain after position 60, so the batch will be a partial last batch of 3 rows. PostgreSQL returns whatever rows exist within the requested window without padding or error.

Output:

  • One row per product in the batch, with columns id, name, and price, sorted by name ascending.
Schema · ecommerce 5 tables
categories
id integer
name text
parent_id? integer
products
id integer
name text
category_id integer
price numeric
stock_qty integer
attributes? jsonb
order_items
id integer
order_id integer
product_id integer
quantity integer
unit_price numeric
customers
id integer
name text
email text
city? text
country text
created_at timestamptz
is_active boolean
orders
id integer
customer_id integer
ordered_at timestamptz
status text
total_amount numeric

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution Try it yourself first
Solution query
SELECT
  id,
  name,
  price
FROM
  products
ORDER BY
  name
LIMIT
  10
OFFSET
  60

The shape

The export tool asks for a batch of 10 starting at row 61, but only 3 products remain past row 60 — LIMIT 10 OFFSET 60 returns those 3 rows and stops without error, which is the last-page shape in every paginated feed.

Clause by clause

  • SELECT id, name, price picks the three columns the export needs per row.
  • FROM products reads the full catalogue — 63 products in total.
  • ORDER BY name sorts alphabetically. The same key has anchored every prior batch, which is what makes "batch starting at position 61" mean the same thing run after run.
  • LIMIT 10 OFFSET 60 requests up to 10 rows after skipping the first 60. The sorted result has 63 rows, so OFFSET 60 lands on row 61 with three rows remaining: Writing Clean Code, Yoga Mat, and Zephyr 12. PostgreSQL returns those three and stops — it doesn't loop back, pad with nulls, or raise an error.

Why this and not a separate query for the partial batch

The export tool doesn't need to know in advance that the last batch is partial. The same query shape — LIMIT 10 OFFSET <page * 10> — handles full batches and the partial trailing batch identically. PostgreSQL evaluates the window, returns whatever rows fall inside it, and the result size is what tells the tool the export is done.

That behaviour is what makes LIMIT work as a ceiling rather than a floor. The clause says "return at most this many," not "return exactly this many." If fewer rows exist past the OFFSET, the smaller set comes back. If more exist, the cap kicks in. Same query, both cases.

The trap

A learner who reads LIMIT 10 as "return 10 rows" can be surprised when the result has 3. The cap is an upper bound, not a contract. The same misread shows up the other direction too — assuming a partial result means something went wrong, when in fact it means the dataset is smaller than the window the query asked for. For an export tool, the right read is the opposite: a result with fewer rows than the LIMIT is the signal that the end of the data has been reached, and the next batch would be empty.

You practiced requesting a window that runs past the end of the data. LIMIT is a ceiling, not a floor — when fewer rows exist after the OFFSET than LIMIT allows, PostgreSQL returns the partial set and stops, which is the recurring shape of the last page in any paginated feed.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.

Practice, feedback, mastery, review. That's the loop that turns reading into real skill.

Start free

No account, no credit card. Start solving in under a minute.