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

后端 未结 7 1757
忘掉有多难
忘掉有多难 2021-01-14 03:27

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

7条回答
  •  情话喂你
    2021-01-14 04:09

    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.

提交回复
热议问题