Update table field to value plus constant in MYSQL without PHP

I would like to execute UPDATE

in MYSQL

which I take the value of a field, add a constant and store the new value in the same field.

Suppose we have a named column OldValue

in a table named aTable

.

The pseudocode could be:

UPDATE aTable SET OldValue = OldValue + 220 WHERE someField = someValue

      

Do you have any ideas on how I can do this? I would like to use a single request (in some dashboard) without creating a php

script. (Of course, in this case, the answer is pretty simple.)

+3


source to share


2 answers


Your code will work.

See how it works in SQLFiddle .



I used your exact query verbatim, except for replacing the real value for "someValue".

+4


source


Here's an example working using pseudocode from the original question itself.



UPDATE `table1` SET `field1` = `field1` - 18, `field2` = `field2` + 16 WHERE n_id IN (111,222,333) OR form IN ('Digital Editing','Studio Room') AND location_id LIKE ('%home-page10%')

      

+3


source







All Articles