ZiggidyCreative ZiggidyCreative - 2 months ago 4x
MySQL Question

How can I write SQL for a table that shares the same name as a protected keyword in MySql?

The following query will not execute

mysql_query("SELECT * FROM order WHERE orderID = 102;");

It produces the following error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order WHERE orderID = 102' at line 2

How can I write SQL that will successfully query this table?


Order is a reserved word. Don't use reserved words as table or field names; or wrap it in the escape characters such as ` for mysql. Personally I just avoid using them as they generally cause more headache than they are worth in the long run.


mysql_query("SELECT * FROM `order` WHERE orderID = 102;");

MORE INFO - you can get more info about reserved word here https://dev.mysql.com/doc/refman/5.5/en/keywords.html