ORDER BY
ORDER BY sorts the result. ASC is ascending (the default) and DESC is descending. You can sort by several columns: the second one breaks ties in the first.
Example
SELECT name, score
FROM students
ORDER BY score DESC;Result
name | score Ada | 92 Zainab | 88 Amina | 85 Kofi | 78 Tunde | 71 Wanjiru | 64 Sipho | 59 Esi | NULL
Example
SELECT name, country, score
FROM students
ORDER BY country ASC, score DESC;Result
name | country | score Kofi | Ghana | 78 Esi | Ghana | NULL Wanjiru | Kenya | 64 Ada | Nigeria | 92 Zainab | Nigeria | 88 Amina | Nigeria | 85 Tunde | Nigeria | 71 Sipho | South Africa | 59
Exercise
Sort from highest to lowest.
SELECT * FROM students ORDER BY score ;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.