LIMIT & OFFSET SQL practice problemMediumVerified answer

Pagination with a Custom Page Size

Return employees 3 and 4 (page 2 with a page size of 2).

  • CTEs
  • Sorting
  • Top-N

Interview brief

Understand the request

HR reporting lead Different departments use different page sizes; this request is for batches of 2.

With page size 5, return page 2 of employees sorted by last_name ascending, employee_id ascending as tie-breaker. Show first_name, last_name, email, employee_id.

Return

  • Return first_name, last_name, and salary.

Constraints

  • Use LIMIT 2 OFFSET 2.

Data you will use

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

employees

  • first_nameTEXT
  • last_nameTEXT
  • emailTEXT
  • employee_idINTEGER

Hints, when you need them

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

Hint 1

Plug into the formula: page 2 with page_size 5 → OFFSET = 5, LIMIT = 5.

Hint 2

Notice that the ORDER BY here is by last_name (text). Rows that share a last_name are broken by employee_id.

Hint 3

ORDER BY last_name, employee_id LIMIT 5 OFFSET 5

Verified SQL answer

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

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

Why this works

Page size is a UX decision: small (10-20) for human scrolling, large (200+) for export. The same SQL pattern serves both — you change the constants, not the structure.

Expected result

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

first_namelast_nameemailemployee_id
MikeJohnsonmike.johnson@company.com3
BrianLeebrian.lee@company.com15
KevinMartinezkevin.martinez@company.com13
AlexMilleralex.miller@company.com11
NicoleRodrigueznicole.rodriguez@company.com14

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics: