Sort Salaries from Lowest to Highest
Return first_name, last_name, salary, and department_id for every employee, ordered by salary from lowest to highest.
- Sorting
Exercise brief
Understand the request
Compensation operations analyst A salary review export must begin with the lowest current salary and remain reproducible.
List employees sorted by salary in ascending order (lowest first). Show first_name, last_name, salary, department_id.
Return
- Return one row per employee.
- Order the final result by salary ascending.
Constraints
- Use an explicit ORDER BY salary ASC clause.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
first_nameTEXTlast_nameTEXTsalaryDECIMALdepartment_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
ORDER BY <column> sorts the result. The default direction is ascending (smallest first).
Hint 2
You can write `ORDER BY salary ASC` explicitly — the ASC keyword is optional.
Hint 3
SELECT first_name, last_name, salary, department_id FROM employees ORDER BY salary;
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, department_id FROM employees ORDER BY salary;Why this works
ORDER BY is the LAST step in logical query processing — it runs after WHERE, GROUP BY, HAVING, and SELECT. Without ORDER BY, the engine may return rows in any order it finds convenient (insertion order is NOT guaranteed).
Success check
All 12 employees appear exactly once in ascending salary order.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | salary | department_id |
|---|---|---|---|
| Emma | Thomas | 52000 | 2 |
| Jane | Smith | 55000 | 2 |
| Lisa | Davis | 58000 | 2 |
| Tom | Wilson | 62000 | 3 |
| Rachel | Garcia | 64000 | 3 |
| Sarah | Williams | 65000 | 3 |
| Chris | Anderson | 68000 | 3 |
| David | Brown | 70000 | 1 |
| Alex | Miller | 72000 | 1 |
| John | Doe | 75000 | 1 |
Previewing 10 of 12 expected rows. Run the query in the editor to inspect the full result.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
LIMIT & OFFSET
Practice deterministic top-N, cutoff ties, offset pagination, composite keyset cursors, and resumable bounded batches.
Ranking & NTH Value
Solve deterministic ranking, top-N, distribution, positional-frame, and rolling-window problems.
SELECT Statements
Select columns, filter rows, remove duplicates, and order query results.
Open the interactive workspace and practice across SQL topics.