08 Nov
2012

mysql logo

MySQL UPDATE a column value with add or subtract

If you have a numerical value in a MySQL database table, that you want to UPDATE by adding a value to it, or subtracting a value from it. This can be done with a single MySQL query.

So for an example, I have a database with a product which has a quantity of 10 in stock, somebody has just bought 5 so I need to subtract that value from the database quantity.

Later in the shop admin you receive new stock and so need to UPDATE the product quantity by adding 5 new items to its current quantity of 5.

avatar

Written by me@grafxflow

I am a freelance designer and developer of all things web - from CSS3 bootstrap responsive layouts through to WordPress and MVC CodeIgniter. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Follow grafxflow on twitter Follow grafxflow on github Follow grafxflow on google+
Tagged: < | | | | | >

1 Thought on "MySQL UPDATE a column value with add or subtract"

  1. 15 Aug
    2013

    avatar

    java tutorial

    Woah this website is excellent i prefer examining the articles you write. Keep up the great get the job done! You understand, lots of individuals need all-around because of this info, you could potentially assist them to drastically.

smart search