ORDER BY Multiple Columns in SQL
Level 380 keystrokes
ORDER BY with several columns sorts by the first column, then by the next one when values are equal.
SQL code
1SELECT -- Returns the name, department and salary columns2 name,3 department,4 salary5FROM6 employees-- Sorts by several columns, from left to right7ORDER BY -- First by department, ascending (ASC is the default)8 department, -- Then, within the same department, by salary from highest to lowest9 salary DESC;Output
+-------+------------+--------+ | name | department | salary | +-------+------------+--------+ | Bob | HR | 55000 | | Alice | HR | 50000 | | Carol | IT | 75000 | | Dan | IT | 65000 | +-------+------------+--------+ 4 rows in set
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this SQL code and how often they appear.
,× 3;× 1