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 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.
Is there a way around it?
This is the line in my SQL query:
SELECT * FROM categories WHERE hide = 0 ORDER BY order
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 :)
If you are working with Postgres just use "column_name", e.g:
SELECT "order" FROM table_name WHERE "order" > 10 ORDER BY "order";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With