LIMIT & OFFSET SQL practice problemEasyVerified answer

Pagination: Page 3

Return page 3 of results (5 employees, starting after the first 10).

  • CTEs
  • Sorting
  • Top-N

Interview brief

Understand the request

HR portal developer The third page of the employee directory starts after 10 already-seen records.

With page size 4, return page 3 of employees ordered by employee_id ascending. Show employee_id, first_name, last_name.

Return

  • Return first_name, last_name, and salary.

Constraints

  • Use LIMIT 5 OFFSET 10.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

employees

  • employee_idINTEGER
  • first_nameTEXT
  • last_nameTEXT

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

Plug into the formula: page 3 with page_size 4 → OFFSET = (3 − 1) × 4 = 8.

Hint 2

There are only 15 employees and we asked for 4 starting at offset 8, so rows 9–12 come back.

Hint 3

LIMIT 4 OFFSET 8

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT employee_id, first_name, last_name FROM employees ORDER BY employee_id LIMIT 4 OFFSET 8;

Why this works

When (OFFSET + LIMIT) exceeds the row count, you simply get fewer rows back — there is no error. Page 4 here would return rows 13–15 (only 3); page 5 would return zero rows. A well-built pagination UI checks if the next page is empty before showing a "Next" button.

Expected result

Use this output to verify values, aliases, ordering, and row count.

employee_idfirst_namelast_name
9ChrisAnderson
10EmmaThomas
11AlexMiller
12RachelGarcia

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics: