Multi-Column Ordering with NULLS
Demonstrates ORDER BY with multiple columns, mixed sort directions, NULLS handling, and expression-based sorting for precise result ordering.
Code
SELECT
employee_id,
first_name,
last_name,
department_id,
hire_date,
salary,
manager_id
FROM employees
ORDER BY
department_id ASC NULLS LAST,
salary DESC NULLS FIRST,
last_name ASC,
CASE
WHEN manager_id IS NULL THEN 0
ELSE 1
END ASC;Report a problem with this exampleOpens a pre-filled issue on GitHub.