views:

29

answers:

3

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

+1  A: 
UPDATE tbl SET col=col+1 WHERE id=1234
Dor
+1  A: 
UPDATE Product SET Quantity = Quantity - 1 WHERE Id = xxx
David M
+1  A: 

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

Steve De Caux
Early bird gets the worm.
andrew