Sorting results using ORDER BY

In some cases, we'd like to display our data in a particular order. The ORDER BY clause lets us pick a column that's used to sort the results. For instance, we might want to display the names and dates of birth of all owners from the earliest date of birth to the latest:

SELECT name, dateOfBirth FROM owners
ORDER BY dateOfBirth

If we add DESC after the name of the column, we can sort in reverse order. For instance, to display the names and dates of birth of all owners from the latest date of birth to the earliest:

SELECT name, dateOfBirth FROM owners
ORDER BY dateOfBirth DESC

Task

What your results should look like

Query

Result

There was an error in your SQL query: {{error}}

{{executedQuery}}

Correct answer. Bonza!

Congratulations! You've completed all of the tasks in this lesson.

This is the last lesson – so far! If have any feedback or suggestions, or would just like to know when there are any more lessons, send us an email at hello@learnsomesql.com.

Wrong answer. Have another a go.

Hint: {{hint}}

Questions? Suggestions?

We'd love to hear any feedback you have for us. Just send an email to hello@learnsomesql.com.