Page 1 of 1
mysql UPDATE question
Posted: Tue Dec 28, 2004 3:18 pm
by bg
Id like to update an INT field in a table, but not with a specific value, instead I would like to increment the existing value. Is this possible without first knowing the existing value of the field?
for example
Code: Select all
UPDATE table
SET field1 = {field1 + 5}
WHERE key_field = our_key;
the code within the {} is obviously where i wouldnt know how to do it. Thanks.
Re: mysql UPDATE question
Posted: Tue Dec 28, 2004 3:24 pm
by protokol
bgzee wrote:Code: Select all
UPDATE table
SET field1 = {field1 + 5}
WHERE key_field = our_key;
Yep, you got it:
Code: Select all
UPDATE table
SET field1 = field1 + 5
WHERE key_field = our_key
Re: mysql UPDATE question
Posted: Tue Dec 28, 2004 3:25 pm
by bg
wow, maybe i should have given it a shot before posting.
thanks.
protokol wrote:bgzee wrote:Code: Select all
UPDATE table
SET field1 = {field1 + 5}
WHERE key_field = our_key;
Yep, you got it:
Code: Select all
UPDATE table
SET field1 = field1 + 5
WHERE key_field = our_key
Posted: Tue Dec 28, 2004 3:27 pm
by protokol
Laziness is human....and wonderful.