Reputation: 5014
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?
Upvotes: 8
Views: 9377
Reputation: 1
The simplest answer is;
UPDATE pages SET pages.order = 1 WHERE id = 19 ;
That should do the trick.
Upvotes: 0
Reputation: 5335
You need to remove the single quote from the column name specification in the query
UPDATE pages SET order = 1 WHERE id = 19 ;
Upvotes: 0
Reputation: 25200
order
is a reserved word used in ORDER BY
.
Use backticks (`) (as Ken said).
Upvotes: 0
Reputation: 1
I think the query should be;
UPDATE pages SET order = '1'
WHERE id = 19
Upvotes: 0
Reputation: 39274
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.
Upvotes: 1
Reputation: 737
If using MySQL the query should look like this:
UPDATE `pages` SET `order`=1 WHERE `id`=19
Upvotes: 9
Reputation: 2944
That looks like a MySQL error message. Doesn't MySQL use backticks (`) for escaping?
Upvotes: 3