Skip to main content
/1 min read

SQL ORDER BY Tutorial

How ORDER BY Works

Sorts Result Rows

Sorts the data based on a specific column or columns.

ASC vs DESC

DESC for descending (top scorers first); default is ASC ascending.

Syntax

SELECT * FROM table ORDER BY column_1 DESC;

Multi-Column Sort

ORDER BY team ASC, points DESC sorts by team then by points within each team.

Master SQL at Noble Desktop

Noble Desktop's SQL Bootcamp covers queries, joins, aggregations, and the full SQL toolkit data analysts use every day.

Learn to use the ORDER BY function in SQL to sort data with our tutorial and screenshots.

ORDER by

  • The ORDER BY keyword is used to sort data in our table.

  • ORDER BY sorts data based on a specific column(s) in either ascending or descending order.

  • Syntax: SELECT * FROM table ORDER BY column_1 DESC ;

Example

Let’s say we have a basketball league and we keep records of each player, which team they are on, and their basic statistics.

Stats Table

If we wanted to use a SQL query to find the top rebounders, we would write the following:

SQL ORDER BY

Once we hit ENTER and run, our result should be as follows:

SQL ORDER BY Result