Preview the First N Rows
Return any 4 employees as a data sample.
- Sorting
- Top-N
Interview brief
Understand the request
Data sampling analyst A random-check audit needs a small representative sample of the employee list.
Preview the first 7 employees by employee_id. Show employee_id, first_name, last_name, department_id.
Return
- Return first_name, last_name, and department_id.
Constraints
- Use LIMIT to cap the result at 4 rows.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
employee_idINTEGERfirst_nameTEXTlast_nameTEXTdepartment_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
For a deterministic preview, sort by a unique column (employee_id) before limiting.
Hint 2
For a RANDOM sample (different rows each run), use ORDER BY RANDOM() — covered in the ORDER BY scenario.
Hint 3
ORDER BY employee_id LIMIT 7
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, department_id FROM employees ORDER BY employee_id LIMIT 7;Why this works
Two different intents people lump under 'sample': (1) deterministic preview = ORDER BY <unique> LIMIT N (this question); (2) random sample = ORDER BY RANDOM() LIMIT N. Pick the one your use-case needs — they're not interchangeable.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| employee_id | first_name | last_name | department_id |
|---|---|---|---|
| 1 | John | Doe | 1 |
| 2 | Jane | Smith | 2 |
| 3 | Mike | Johnson | 1 |
| 4 | Sarah | Williams | 3 |
| 5 | David | Brown | 1 |
| 6 | Lisa | Davis | 2 |
| 7 | Tom | Wilson | 3 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics: