Basics · Lesson 5 of 19

Sorting with ORDER BY

ORDER BY sorts your results.

Ascending (smallest to largest) - default:

SELECT * FROM employees ORDER BY salary;

Descending (largest to smallest):

SELECT * FROM employees ORDER BY salary DESC;

Sort by multiple columns:

ORDER BY department_id, salary DESC

This sorts by department first, then by salary within each department.

Check your understanding

List all employees sorted by salary from highest to lowest.

Examples run on the employees sample database. Open any of them in the playground to experiment.