asterisk-solid Classes available in-person (strict social distancing) or live online with an extended free retake period. See details.

window-close-line
Hero image for SQL ORDER BY Tutorial

SQL ORDER BY Tutorial

SQL Tutorial: ORDER BY with Example

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

Master SQL in hands-on training