SQL query: Can't order by column called “order”?

谁说我不能喝 提交于 2019-12-01 12:39:23
Jamesking56

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`

Try that :)

Try using backticks:

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

ORDER is a reserved word in SQL. You can use a reserved word as a column name but you must surround it in backticks when referencing it. It's good practice to surround all your column names in backticks so you don't run into this issue.

Try using back ticks around the column name, that should do it.

From the manual:

A reserved word can be used as an identifier if you quote it.

So you can use it like this:

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

AS orderis a SQL keyword, you should escape it properly as an field identifier by using backticks:

SELECT ... FROM ... ORDER by `order`

Worked for me with brackets. SELECT T.* FROM dbo.test AS T ORDER BY [T].[ORDER]

If you are working with Postgres just use "column_name", e.g:

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