LIMIT & OFFSET SQL practice problemEasyVerified answer

Pagination: Page 1

Return the first page of results (5 employees, starting from the beginning).

  • CTEs
  • Sorting
  • Top-N

Interview brief

Understand the request

People operations coordinator The first page of the paginated employee list shows 5 records per page.

With page size 4, return page 1 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 0.

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

OFFSET = (page_number - 1) * page_size. For page 1: OFFSET = 0.

Hint 2

`LIMIT 4 OFFSET 0` is identical to `LIMIT 4` — but writing it explicitly makes the formula obvious.

Hint 3

ORDER BY employee_id LIMIT 4 OFFSET 0

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 0;

Why this works

Always store ORDER BY <unique-column> with pagination. Without a stable order, pages can overlap or skip rows when the data changes between page loads — a classic real-world bug.

Expected result

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

employee_idfirst_namelast_name
1JohnDoe
2JaneSmith
3MikeJohnson
4SarahWilliams

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics: