It is often necessary to be able to make a systematic display of the captured data. This may be by small toward large (ascending) or by large toward small (descending). In this case, we can use order by as an order to achieve our purpose.
The syntax for ORDER by IS as follows:
SELECT from [WHERE "condition"] ORDER by [ASC, DESC];
[] to represent WHERE is a must. However, if the where clause exists, it is before the ORDER by clause. The ASC represents the results in a small, large order, and DESC indicates that the results are listed in a small order. If neither is written, then we will use ASC.
We can arrange the order according to several different fields. In this case, the syntax for theORDER by clause is as follows (assuming there are two fields):
ORDER by [ASC, DESC] [ASC, DESC]
If we choose between these two fields from small to large, then this clause will cause the result is based on "column one" from small to large rows. If there are several pieces of information "field one" value is equal, then these data will be based on "column two" from the small to large row.
SELECT from ORDER by DESC;
Results:
Los Angeles theJan- to-1999Boston theJan- ,-1999San Francisco -Jan- ,-1999San Diego -Jan- --1999
In the example above, we use the field names to specify the order of the columns. In addition to the column names, we can also use the order of the fields (according to the order in the SQL sentence). The first field after a SELECT is 1, the second field is 2, and so on. In the above example, we can achieve exactly the same result in SQL:
SELECT from ORDER by 2 DESC;
Sql-order by