UPDATE Adding values

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
gastonlm
Forum Commoner
Posts: 26
Joined: Tue May 07, 2002 10:19 am
Location: Buenos Aires, Argentina
Contact:

UPDATE Adding values

Post by gastonlm »

I have to update a table where a field is numeric. I want to update that field adding 4 to that field. For example, if I have the number 100, when the table is updated, the field shuold be 104. If the field has the value 800, after updating the value should be 804. Hoy can I do that with an SQL UPDATE Statement?
I hope my explanation had been clear.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

UPDATE table SET col_1 = col_1+4 WHERE ....
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

Code: Select all

$query = "UPDATE table SET field = field + 4 WHERE id = $id";
mysql_query($query);
simple as that :)
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

hehe, got beat to it :o
Post Reply