Learn SQL Lesson

LIMIT Happens at the End

`LIMIT` is one of the last steps. It cuts down the final ordered result, not the raw table.

So in a query like:

SELECT name, salary
FROM employees
WHERE department = 'Engineering'
ORDER BY salary DESC
LIMIT 2

SQL first filters to Engineering, then sorts those rows, and only then keeps the top 2.

If `LIMIT` happened earlier, you would often get the wrong rows.

Practice challenge

Show the top 2 highest-paid Engineering employees. Return name and salary, ordered by salary descending.

Open interactive editor