Syntax error near “ORDER BY order DESC” in MySQL?

守給你的承諾、 提交于 2019-12-01 08:13:35

order is a reserved word in SQL; case does not matter. It must be quoted when used as an identifier. From the MySQL Reserved Words documentation:

Certain words such as SELECT, DELETE, or BIGINT [or ORDER] are reserved and require special treatment for use as identifiers such as table and column names.

Traditional MySQL quotes:

SELECT * FROM posts ORDER BY `order` DESC;

Proper (ANSI) SQL quotes (some databases support [order] as well):

SELECT * FROM posts ORDER BY "order" DESC;

Although I would consider renaming the column to avoid such confusing issues in the future.

Happy coding!

Order is reserved keyword.

Try,

SELECT * FROM posts ORDER BY `order` DESC;

The column name is order which is a keyword. You need to do this:

SELECT * FROM posts ORDER BY `order` DESC;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!