LIMIT & OFFSET SQL practice problemEasyVerified answer

SQL Server: TOP N

Return the 5 employees with the LOWEST salary using SQL Server's `TOP N` syntax (write the canonical SQLite version with LIMIT here; the SQL Server variant is in solutionsByEngine). Tie-breaker: employee_id ascending. Show first_name, last_name, salary, employee_id.

  • CTEs
  • Sorting
  • Top-N

Interview brief

Understand the request

Return the 5 employees with the LOWEST salary using SQL Server's `TOP N` syntax (write the canonical SQLite version with LIMIT here; the SQL Server variant is in solutionsByEngine). Tie-breaker: employee_id ascending. Show first_name, last_name, salary, employee_id.

Data you will use

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

employees

  • first_nameTEXT
  • last_nameTEXT
  • salaryDECIMAL
  • employee_idINTEGER

Hints, when you need them

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

Hint 1

SQL Server: SELECT TOP N ... FROM ... ORDER BY ... (TOP is between SELECT and the column list).

Hint 2

TOP N is non-standard but widely used in Microsoft shops. Knowing it is essential for SQL Server work.

Hint 3

SELECT TOP 5 ... FROM employees ORDER BY salary, employee_id;

Verified SQL answer

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

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

Why this works

On SQL Server you can also write `TOP (N)` with a variable: `SELECT TOP (@n) …`. Without parentheses TOP only accepts a literal. There is also `TOP N PERCENT` for "the top 10% of rows".

Expected result

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

first_namelast_namesalaryemployee_id
EmmaThomas5200010
JaneSmith550002
NicoleRodriguez5600014
LisaDavis580006
TomWilson620007

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics: