使用 MySQL 的 ORDER BY 子句来设定你想按哪个字段哪种方式来进行排序,再返回搜索结果。
语法
SELECT field1, field2,...fieldN FROM table_name1, table_name2...
ORDER BY field1 [ASC [DESC][默认 ASC]], [field2...] [ASC [DESC][默认 ASC]]
实例
mysql> SELECT * from runoob_tbl ORDER BY submission_date ASC;
+-----------+--------------+---------------+-----------------+
| runoob_id | runoob_title | runoob_author | submission_date |
+-----------+--------------+---------------+-----------------+
| 3 | JAVA 教程 | RUNOOB.COM | 2016-05-06 |
| 1 | 学习 PHP | 菜鸟教程 | 2019-09-18 |
| 2 | 学习 MySQL | 菜鸟教程 | 2019-09-18 |
+-----------+--------------+---------------+-----------------+
3 rows in set
mysql> select * from runoob_tbl order by submission_date desc;
+-----------+--------------+---------------+-----------------+
| runoob_id | runoob_title | runoob_author | submission_date |
+-----------+--------------+---------------+-----------------+
| 1 | 学习 PHP | 菜鸟教程 | 2019-09-18 |
| 2 | 学习 MySQL | 菜鸟教程 | 2019-09-18 |
| 3 | JAVA 教程 | RUNOOB.COM | 2016-05-06 |
+-----------+--------------+---------------+-----------------+
3 rows in set
原文:https://www.cnblogs.com/Stephanie-boke/p/11664509.html