LIMIT & OFFSET SQL practice problemMediumVerified answer

OFFSET Without LIMIT (Engine-Specific)

Return employees starting from the 6th record onward.

  • Sorting
  • Top-N

Interview brief

Understand the request

Data migration engineer The second batch of the migration starts after the first 5 exported records.

Skip the first 10 employees and return everything that remains. Show first_name, last_name, hire_date, employee_id, ordered by employee_id ascending.

Return

  • Return all employee columns.

Constraints

  • Use OFFSET 5 without a LIMIT cap.

Data you will use

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

employees

  • first_nameTEXT
  • last_nameTEXT
  • hire_dateDATE
  • employee_idINTEGER

Hints, when you need them

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

Hint 1

OFFSET-only behaviour differs by engine: SQLite needs `LIMIT -1`, PostgreSQL accepts `OFFSET 10` alone or `LIMIT ALL OFFSET 10`, MySQL needs a giant LIMIT, SQL Server uses `OFFSET 10 ROWS`.

Hint 2

When portability matters, prefer always specifying a LIMIT — make it artificially large if you really want the rest.

Hint 3

ORDER BY employee_id LIMIT -1 OFFSET 10

Verified SQL answer

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

Reveal solution and explanation
SELECT first_name, last_name, hire_date, employee_id FROM employees ORDER BY employee_id LIMIT -1 OFFSET 10;

Why this works

This is one of the few places where there is no portable shorthand for "the rest". The standard SQL form (`OFFSET 10 ROWS`) works on PostgreSQL and SQL Server but not on MySQL or SQLite below 3.39. Knowing the engine lets you pick the right idiom.

Expected result

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

first_namelast_namehire_dateemployee_id
AlexMiller2019-08-1411
RachelGarcia2020-11-3012
KevinMartinez2021-03-1813
NicoleRodriguez2020-07-2214
BrianLee2019-12-0515

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics: