Home > Database > Mysql Tutorial > body text

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

王林
Release: 2023-09-12 14:53:02
forward
1184 people have browsed it

在 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!