"ORDER BY order DESC"附近的语法错误;在MySQL中? [英] Syntax error near "ORDER BY order DESC" in MySQL?

查看:108
本文介绍了"ORDER BY order DESC"附近的语法错误;在MySQL中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我尝试按查询进行排序,但总是收到一个错误,告诉我要通过ORDER BY'order'DESC ...来检查语法.这是我的查询:

Why I try to do an order by query, I always get an error telling me to check the syntax by the ORDER BY 'order' DESC.... Here's my query:

SELECT * FROM posts ORDER BY order DESC;

我在做什么错??

推荐答案

order是SQL中的保留字;大小写无关紧要.当用作标识符时,必须使用引用.从 MySQL保留字文档:

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:

某些词(例如SELECT,DELETE或BIGINT [或ORDER])已保留,需要特殊处理才能用作表和列名之类的标识符.

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.

传统的MySQL引号:

Traditional MySQL quotes:

SELECT * FROM posts ORDER BY `order` DESC;

正确的(ANSI)SQL引号(某些数据库同时支持[order]):

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.

祝您编程愉快!

这篇关于"ORDER BY order DESC"附近的语法错误;在MySQL中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆