1

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)

3 Answers 3

2
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

Sign up to request clarification or add additional context in comments.

Comments

1
UPDATE tbl SET col=col+1 WHERE id=1234

Comments

1
UPDATE Product SET Quantity = Quantity - 1 WHERE Id = xxx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.