Skip to content
Advertisement

How do I update a table with old value + the new value?

I have this SQL string which updates a row if it exists or creates a row if it does not, how do I do if it updates ctc_portfolio_coins_amount

If I have a value of 100, or -100, how do I either substract it or add it to the current value when it updates?

Table:

enter image description here

Advertisement

Answer

Arithmetic:

The reference to ctc_portfolio_coins_amount is the value in the column before the update. The reference to VALUES(ctc_portfolio_coins_amount) is the value passed into the INSERT statement.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement