Home  >  Article  >  Database  >  In MySQL, how to specify a sort order using columns not retrieved by a query?

In MySQL, how to specify a sort order using columns not retrieved by a query?

王林
王林forward
2023-09-12 14:53:021158browse

在 MySQL 中,如何使用查询未检索到的列来指定排序顺序?

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.

Example
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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete