Question

Here is an easy question for someone. 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) Thanks Andrew

Was it helpful?

Solution

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

OTHER TIPS

UPDATE tbl SET col=col+1 WHERE id=1234
UPDATE Product SET Quantity = Quantity - 1 WHERE Id = xxx
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top