ORDER BY clause
The syntax for the ORDER BY clause is:
SELECT Column1, SUM (Column2)
From "List-of-tables"
ORDER BY "Column-list" [ASC | DESC];
[] = optional
An order BY is an optional clause that allows you to display the results of a query according to the ascending or descending sequence of the columns that you specify to be ordered by. For example:
ASC = Ascending order– This is the default
DESC = descending order
Here's an example:
SELECT employee_id, Dept, name, age, salary
From Employee_info
WHERE dept = ' Sales '
Order by salary;
This SQL statement will list the dept equals ' Sales ' to select employee_id, dept, name, age, and salary from the Employee_info table, and list the results in ascending order according to their salary.
If you want to sort multiple columns, add commas between columns and columns, such as:
SELECT employee_id, Dept, name, age, salary
From Employee_info
WHERE dept = ' Sales '
Order by salary, age DESC;