Reputation: 271
I can't use 'time' word as my column name in mysql query.
This is my query code:(Not Working)
UPDATE ip_p SET deger = '-1' TIME = '123' WHERE ip = '12' AND premium = '1'
Error is:
#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 'time='123' WHERE ip = '12' AND premium = '1'' at line 1
But this code is working:
UPDATE ip_p SET deger = '-1' WHERE ip = '12' AND premium = '1'
Will I have to change my column name?
Upvotes: 0
Views: 1544
Reputation: 10532
1) You're missing coma (,) after deger = '-1'
2) You may enclose TIME into backticks (`) to prevent other possible errors
Correct (try it?) query spelling:
UPDATE ip_p SET deger = '-1', `TIME` = '123' WHERE ip = '12' AND premium = '1'
UPDATE
Responding to comment:
correct query for decreasing deger
column by 1 will be:
UPDATE ip_p SET deger = deger-1, `TIME` = '123' WHERE ip = '12' AND premium = '1'
If you just need to set it to -1 then do:
UPDATE ip_p SET deger = -1, `TIME` = '123' WHERE ip = '12' AND premium = '1'
Also please note that syntax with single quotes (') should be used only with strings (varachar(...) columns etc.); for numbers that is incorrect. If you need to specify the number - just do it without any quotes. I've changed this for deger
column (apparently it's numeric if you want to subtract something from it) but not for the others because I don't know their types. If columns TIME
, ip
and premium
are also numbers then you'll need to also remove quotes from their values.
Upvotes: 3
Reputation: 234857
You're missing a comma before TIME
:
UPDATE ip_p SET deger = '-1', TIME = '123' WHERE ip = '12' AND premium = '1'
^
Upvotes: 0
Reputation: 324790
You can, but you must enclose the name in backticks `
. As a general rules I always enclose column names in them, as it makes it clear what they are.
Upvotes: 0
Reputation: 98559
You can escape the keyword "time" by using backticks:
UPDATE ip_p SET deger = '-1', `TIME` = '123' WHERE ip = '12' AND premium = '1'
I believe you also dropped a comma, which may be the cause of the error you are getting here. But in general, if you have a column name which is special to MySQL, escape it.
Upvotes: 1