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 Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

SQL ORDER BY

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

SQL ORDER BY Result

How to Learn SQL

Master SQL with Hands-on Training. SQL is One of the Most In-demand Programming Languages and is Used Across a Variety of Professions.

Yelp Facebook LinkedIn YouTube Twitter Instagram