# LIMIT: maximum number of rows

Especially when paired with sorting, it can be useful to limit the number of rows in the result set.

That way you can get the "10 most experienced" employees. Or the "10 highest paid employees".

Something like this:

SELECT * FROM employees
ORDER BY years_experience DESC
LIMIT 10;

This would limit the result set to a maximum of 10 rows. If there are fewer rows, only those would be returned. If there are more rows only the first 10 would be returned, according to the sorting order.

LIMIT goes at the end of the query.

# LIMIT without ORDER BY

Limiting the number of rows without ORDER BY loses some usefulness, but can still be done:

SELECT * FROM employees
WHERE salary > 100000
LIMIT 10;

Or you can just do it without any filtering or sorting at all, to get the 10 rows that were first inserted in the table:

SELECT * FROM employees LIMIT 10;