解决 MySQL 中"ORDER BY order DESC"附近的语法错误?
mysqlmysqli database更新于 2025/7/19 18:52:17
order 一词是 MySQL 中的保留顺序,您在查询中使用了它。要消除语法错误,您需要在 order 周围使用反引号 (` `)。
正确的语法如下 −
select *from yourTableName ORDER BY `order` DESC;
首先我们创建一个表 −
mysql> create table DemoTable ( `order` int ); Query OK, 0 rows affected (0.58 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.13 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
+-------+ | order | +-------+ | 89 | | 67 | | 90 | | 56 | +-------+ 4 rows in set (0.00 sec)
以下是删除 ORDER BY 附近的语法错误的查询 −
mysql> select *from DemoTable ORDER BY `order` DESC;
输出
+-------+ | order | +-------+ | 90 | | 89 | | 67 | | 56 | +-------+ 4 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

