strawquery PT
All lessons

Lesson 8 of 30

Sorting the results

Today at the studio

Part two of your first month starts with a pile of requests that all say "in order, please". Nobody agrees on which order. Byte votes for "by how soft they are".

The idea

ORDER BY sorts the result. The default is ascending, from small to large and from A to Z. Add DESC for the other direction.

You can sort by several columns. The second one only breaks ties from the first. Without ORDER BY, the database may return rows in any order, so never count on it.

Example

SELECT product, units_sold FROM merch ORDER BY units_sold DESC

Your turn

0 of 4 questions

Question 1 of 4

List everyone's name and salary, highest salary first.

The order of the rows counts in this question.

Unofficial fan project. Titles belong to their creators and rights holders.