Page 1 of 1

msyql_query("SELECT RESERVED FROM table

Posted: Fri Sep 03, 2010 10:02 pm
by ThaJock
I have a query that won't work I assume because the field I'm querying is named order

SELECT id,name,order FROM tablename

How should I write this query?

Re: msyql_query("SELECT RESERVED FROM table

Posted: Fri Sep 03, 2010 10:12 pm
by Jonah Bron
What exactly are you trying to do?

Re: msyql_query("SELECT RESERVED FROM table

Posted: Fri Sep 03, 2010 10:54 pm
by ThaJock
I'm trying to select a field named "order" from a table.

Re: msyql_query("SELECT RESERVED FROM table

Posted: Sat Sep 04, 2010 6:17 pm
by mikosiko
order is a MYSQL reserved word
http://dev.mysql.com/doc/refman/5.1/en/ ... words.html

you have 2 options:
a) enclose your "order" field in backticks i.e

Code: Select all

 SELECT id, name, `order` FROM tablename
but that solution make your select less portable to a different database engine

or
b) rename your "order" field to something else that is nor a reserved word... This should be the preferred option when possible for portability.