ORDER BY Keyword
The Order By keyword or command is used to sort the data in ascending or descending order.
If we want to display data in ascending order, we can do so by using the ASC keyword. To learn more about the ASC keyword, Click Here.
If we want to display data in ascending order, we can use the DESC keyword. To learn more about the DESC keyword, Click Here.
If you do not specify Asc or Desc, then by default it sorts in ascending order.
Syntax
SELECT * FROM <TABLE_NAME> ORDER BY <COLUMN_NAME> ASC/DESC;
Example 1
SELECT * FROM Employee ORDER BY Emp_Name;
Example 2
SELECT * FROM Employee ORDER BY Emp_Name ASC;
Example 3
SELECT * FROM Employee ORDER BY Emp_Name DESC;
Example 4
SELECT * FROM Employee ORDER BY Emp_Name DESC,Emp_Id ASC;
Example 5
SELECT * FROM Employee ORDER BY Emp_Name,Emp_Id,Emp_Age DESC;
Summary
The Order By keyword or command is used to sort the data.