If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

SQL: SELECT with ORDER BY

When you issue a SELECT, the rows often get returned in the same order they were inserted in the table. You can change the order of the rows by adding an ORDER BY clause at the end of your query, with a column name after.
By default, the ordering will be in ascending order, from lowest value to highest value. To change that to descending order, specify DESC after the column name. To be explicit that it's in ascending order, specify ASC.
You can specify multiple column names after ORDER BY if you want to sort by one column and then the other(s), in order.
▶️ You can also learn about this in our Querying the table talkthrough.

Want to join the conversation?

No posts yet.