Ascending sort:
When you use the ORDER BY clause, by default the data is sorted ascending, so you can use the ASC keyword pointing in ascending order, or unspecified, the default is ascending and the display is the same, as in the following figure:
Descending sort:
When you want query results to be sorted in descending order, you must specify the DESC keyword after sorting. The following figure is a descending arrangement to view employee salaries:
Common usage
To sort by using a non-select list:
Sorted columns can also not appear in the select list. The following figure:
To sort by using an expression:
Arithmetic expressions can appear in the columns of select, and expressions can be used to sort by expressions to evaluate the results. The following figure:
To sort using column aliases:
When you make a select query, you can define aliases for columns or expressions, and you can use aliases for sorting when you perform sorting. The following figure:
To sort by using column positions:
We can also sort by the position of the column or expression in the select list, which also effectively reduces the length of the sort statement. In addition, when you use a collection operator such as union, if the column name of the select list is different, you must sort by using the column position. The following figure: a standard that is sorted in ascending order with departmental codes and staff codes.
Use multiple column sorting:
When you perform an action, you can also sort by multiple columns. When more than one column is used as a sorting criterion, the first column is sorted first, if the first column data is the same, and then the second column is sorted, and so on. The following figure: