Menu
Coddy logo textTech

Sort Results Part 1

Part of the Fundamentals section of Coddy's SQL journey — lesson 13 of 72.

When querying a database, organizing your results in a meaningful order can make data analysis much more efficient. To sort the result we use the ORDER BY keyword and after that, we should specify by which field we are ordering by. By default, it sorts by ascending order.

For example consider the following <strong>competition</strong> table:

runner_idageavg_speed
1473.65
2623.07
3576.82
4564.34
5254.93
6403.94
7236.58
8403.43
SELECT *
FROM competition
WHERE age > 50
ORDER BY avg_speed

This is the result

runner_idageavg_speed
2623.07
4564.34
3576.82

To specify how to sort that data we can add DESC or ASC keywords after the name of the column.

ORDER BY avg_speed ASC
challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>feathers</strong>: <strong>id</strong>, <strong>weight</strong>

Return all of the ids after ordering them by the weight in descending order

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals