SQL 查询:不能按名为“order"的列排序? [英] SQL query: Can't order by column called "order"?

查看:14
本文介绍了SQL 查询:不能按名为“order"的列排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将现有脚本中的一列提取到我的模板文件中,并且一切正常.

I am pulling a column in an existing script into my template files, and everything is working great.

唯一的问题是,这个脚本有一个名为 order 的列,然后每一行在该列中都有一个数字来显示哪个应该在顶部等.如果我将查询设置为例如,ORDER BY name",一切正常,但是当我使用ORDER BY order"时,出现 SQL 错误.
我可以没有名为 order 的列吗?我无法更改列名,因为它是脚本的一部分.

The only problem is, that this script has a column called order, and every row then has a number in that column to show which should be at the top etc. If I set my query to "ORDER BY name" for example, everything works fine, but when I use "ORDER BY order", then I get a SQL error.
Can I not have a column called order? I can't change column name, because it's part of the script.

有办法解决吗?

这是我的 SQL 查询中的一行:

This is the line in my SQL query:

SELECT * FROM categories WHERE hide = 0 ORDER BY order 

推荐答案

order 是 SQL 中的关键字.因此,如果您希望使用关键字作为名称,请在其周围使用反引号:

order is a keyword in SQL. So if you wish to use a keyword as a name, use backtick characters around it:

SELECT * FROM categories WHERE hide = 0 ORDER BY `order`

试试看:)

这篇关于SQL 查询:不能按名为“order"的列排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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