ORDER BY in SQL

Level 241 keystrokes

ORDER BY sorts the result set by a specified column.

SQL code

-- Returns the name and age columns of users
-- ORDER BY age sorts by age, ascending (ASC) by default
1SELECT name, age FROM users ORDER BY age;

Output

+-------+-----+
| name  | age |
+-------+-----+
| Alice |  25 |
| Bob   |  30 |
| Carol |  35 |
+-------+-----+
3 rows in set
Practice typing this code

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.

  • ,× 1
  • ;× 1

More SQL examples at level 2

← SQL typing practice