Use the ORDER BY keyword to sort results with a SELECT statement. You can sort over multiple columns, in both ascending and descending order.
Here products are sorted by ListPrice
ORDER BY Multiple Fields
You can sort by more than one field. Separate each column with a comma.
ORDER BY Keyword and DESC
To sort a column in descending (9-0) order use the DESC keyword.
ORDER BY and ASC
To sort in ascending order (0-9) use ASC, which stand for Ascending.
This is the default behavior, so you can opt to leave it off, as we did in the first examples.
In summary use the ORDER BY keyword to sort your result.
You can specify one or more columns.
Place either DESC or ASC after each column to sort them in descending or ascending order, respectively.
Additional Resources
To learn more about the ORDER BY, check out these useful resources:
- In-depth article on Sort Your Query Results
- Good Question! What is the Difference between GROUP BY and ORDER BY?
- Recommended book SQL Practice Problems: 57 beginning, intermediate, and advanced challenges for you to solve using a “learn-by-doing” approach