Sql Query: Can't Order By Column Called "order"?
I am pulling a column in an existing script into my template files, and everything is working great. The only problem is, that this script has a column called order, and every row
Solution 1:
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 =0ORDERBY `order`
Try that :)
Solution 2:
If you are working with Postgres just use "column_name", e.g:
SELECT"order"FROM table_name WHERE"order" > 10ORDERBY"order";
Solution 3:
Try using backticks:
SELECT * FROM `categories` WHERE `hide` = 0ORDERBY `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.
Solution 4:
Try using back ticks around the column name, that should do it.
Solution 5:
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 = 0ORDERBY `order`
Post a Comment for "Sql Query: Can't Order By Column Called "order"?"