Page 1 of 1

UPDATE Adding values

Posted: Wed Aug 14, 2002 10:10 am
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.

Posted: Wed Aug 14, 2002 10:20 am
by Wayne

Code: Select all

UPDATE table SET col_1 = col_1+4 WHERE ....

Posted: Wed Aug 14, 2002 10:21 am
by fatalcure

Code: Select all

$query = "UPDATE table SET field = field + 4 WHERE id = $id";
mysql_query($query);
simple as that :)

Posted: Wed Aug 14, 2002 10:22 am
by fatalcure
hehe, got beat to it :o