解决 MySQL 中“ORDER BY order DESC”附近的语法错误?
单词 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)
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP