tags:

views:

163

answers:

6

I know SQL well but I must be missing something really dumb here. This update query keeps throwing an error. The query is:

UPDATE pages SET 'order' = 1 WHERE id = 19

The table definitely has a column for order, and it has a record with the ID of 19. The order column is not unique.

The error I get is the generic one:

#1064 - 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" = 2 WHERE id = 19' at line 1 

I've enclosed order in quotation marks because ORDER is a reserved SQL word. What am I missing?

+3  A: 

That looks like a MySQL error message. Doesn't MySQL use backticks (`) for escaping?

Ken
+3  A: 

UPDATE pages SET [order] = 1 WHERE id = 19

Nevemind MySQL

Dustin Laine
It says "MySQL" right in the error message. :-)
Ken
Interestingly, that didn't work either. Even though I immediately recognized what you were saying and was sure that was it.
Jason Rhodes
+1  A: 

don't use quotes, use [order] (or whatever your sql version uses for escaping). With the regular quotes it is seen as a string literal, which is not allowed here.

Hans Kesting
A: 
pavun_cool
This won't work. ORDER is a reserved word, and so it must be escaped (which is database-specific)
Tim Drisdelle
+6  A: 

If using MySQL the query should look like this:

UPDATE `pages` SET `order`=1 WHERE `id`=19
Tobias
Only backticks worked, but you only need them around the reserved word, order. So it's UPDATE pages SET `order`=1 WHERE id = 19 LIMIT 1. I was sure square brackets would have worked, I have to look into why they didn't.
Jason Rhodes
Note that you don't have to escape every word (as shown in the example). Only `order`.
Tim Drisdelle
Yes, you do not have to escape every word.But for better understanding (and I think its good practice) to escape the table and row names.[edit] Here is a list of reserved words foy mysql: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
Tobias
A: 

"order" is a reserved word used in ... ORDER BY .... Use (`) (as Ken said).

lepe