问题描述
为什么我尝试按查询进行排序,但总是收到一个错误,告诉我要通过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:
传统的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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!