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](/images/stats_table.PNG)
If we wanted to use a SQL query to find the top rebounders, we would write the following:
![SQL ORDER BY](/images/sql-orderby.PNG)
Once we hit enter and run, our result should be as follows:
![SQL ORDER BY Result](/images/orderby-result.PNG)