Home >Database >Mysql Tutorial >In MySQL, how to specify a sort order using columns not retrieved by a query?
Actually, we know that we can specify the sort order with the help of the ORDER BY clause. We need to write the ORDER BY keyword followed by the name of the column on which we want to sort the table. We don't have to use the column name after the SELECT keyword in the query.
mysql> Select Sr, Item from ratelist ORDER BY Price; +----+------+ | Sr | Item | +----+------+ | 5 | T | | 1 | A | | 2 | B | | 4 | h | | 3 | C | +----+------+ 5 rows in set (0.00 sec)
In the above example, we can observe that we do not need to write the name of the same column after the SELECT keyword written in the ORDER BY keyword to sort the table. This means that the column itself is not retrieved by the MySQL query and we sort the table based on this.
The above is the detailed content of In MySQL, how to specify a sort order using columns not retrieved by a query?. For more information, please follow other related articles on the PHP Chinese website!