Debrah Debrah - 1 year ago 70
PHP Question

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

, 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 "
" 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
? 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

Answer Source

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 :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download