N008-M3 Tier 1 · Foundations · medium analytics · Streamhub

Return the ID, name, and email of the accounts on that page

Part of LIMIT and OFFSET in SQL

The problem

Streamhub's user management dashboard paginates accounts alphabetically by name in pages of 10. An admin is navigating to page 3.

Write a query to return the ID, name, and email of the accounts on that page.

Assumptions:

  • The users table contains every account on the Streamhub platform.
  • Page 1 is rows 1–10, page 2 is rows 11–20, page 3 is rows 21–30.
  • To land on page 3, skip the first 20 rows with OFFSET 20, then take the next 10 with LIMIT 10.

Output:

  • One row per user on page 3, with columns id, name, and email, sorted by name ascending.
Schema · analytics 5 tables
users
id integer
name text
email text
country text
plan text
signed_up_at timestamptz
is_active boolean
conversions
id integer
user_id integer
converted_at timestamptz
plan text
amount numeric
sessions
id integer
user_id integer
started_at timestamptz
ended_at? timestamptz
event_count integer
events
id integer
user_id integer
session_id? integer
event_type text
occurred_at timestamptz
properties? jsonb
periods
id integer
name text
start_month integer
end_month integer

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,
  email
FROM
  users
ORDER BY
  name
LIMIT
  10
OFFSET
  20

The shape

Page 3 of a 10-row pagination is rows 21 through 30, which means skipping the first 20 rows and taking the next 10 — OFFSET 20 LIMIT 10 on top of the alphabetical sort.

Clause by clause

  • SELECT id, name, email picks the three columns the dashboard shows per account. Other user fields stay out.
  • FROM users reads every Streamhub account. The pagination cut happens after the sort.
  • ORDER BY name sorts alphabetically — the same key the dashboard uses to define what page 3 means. Ascending is the default.
  • LIMIT 10 OFFSET 20 carves the page-3 window out of the sorted result. OFFSET 20 discards the first 20 names (pages 1 and 2 combined), and LIMIT 10 returns the next 10. Finn Kim at row 21 lands as the first row of page 3.

Why OFFSET 20 and not OFFSET 30

The formula is OFFSET = (page - 1) * page_size. For a page size of 10:

  • Page 1: OFFSET 0 (no rows skipped, return rows 1–10)
  • Page 2: OFFSET 10 (skip first page, return rows 11–20)
  • Page 3: OFFSET 20 (skip first two pages, return rows 21–30)

The off-by-one is in the (page - 1). Page 3 doesn't skip 30 rows — that would land on page 4. It skips the rows that belong to the pages before page 3, which is 20.

The trap

The instinctive arithmetic — multiply the page number by the page size — overshoots by one page every time. OFFSET 30 LIMIT 10 returns rows 31–40, which is page 4. The fix is the - 1: subtract one from the page number before multiplying. A second trap to watch for: changing the page size also changes the offset. A page of 25 at page 3 is OFFSET 50, not OFFSET 20. The offset is anchored to the page size, not to the page number alone.

You practiced computing the OFFSET from a page number. The recurring formula is OFFSET = (page - 1) * page_size — once internalised, any page of any size becomes a one-line query.

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.