Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
bg
Forum Contributor
Posts: 157 Joined: Fri Sep 12, 2003 11:01 am
Post
by bg » Tue Dec 28, 2004 3:18 pm
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.
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Tue Dec 28, 2004 3:24 pm
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
Post
by bg » Tue Dec 28, 2004 3:25 pm
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
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Tue Dec 28, 2004 3:27 pm
Laziness is human....and wonderful.