mysql UPDATE question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

mysql UPDATE question

Post 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.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Re: mysql UPDATE question

Post 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
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Re: mysql UPDATE question

Post by bg »

wow, maybe i should have given it a shot before posting. :D

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
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Laziness is human....and wonderful.
Post Reply