SQL - ORDER BY

Overview

ORDER BY sorts the result set. Use ASC/DESC per column. Some engines support NULLS FIRST/LAST.

SELECT first_name, salary
FROM employees
ORDER BY salary DESC, first_name ASC;
SELECT first_name, salary
FROM employees
ORDER BY salary DESC, first_name ASC;
SELECT first_name, salary
FROM employees
ORDER BY salary DESC, first_name ASC;

Prerequisite

Load the Standard Test Data.

Expected Output

first_namesalary
Eli130000
Ada120000
Dee110000
Bob90000
Chen80000