Reputation: 5176
When using MySQL, how do you increase or decrease the number in a particular cell by a specified amount with a single query. For example I have a product table with 5 x product a. I sell 1 item and I want to update the field. I want to do it with one query, not get the number add to it and then update (I know how to do that)
Upvotes: 1
Views: 575
Reputation: 1779
update products set amount = amount + 1 where productId = 12345
If you are using prepared statements you can replace the amount to add as well as the product id with placeholders
Upvotes: 2