My MySQL table looks as follows:
Item_Id Item_Name quantity
1 HPWT 20 20
The quantity field is an integer.
Now, if I bought this "HPWT 20" item again with quantity "5" , I want my table affected as follows:
Item_Id Item_Name quantity
1 HPWT 20 25
What I always do is: first I select the previous quantity from the database, then add new quantity to it, then update the quantity with new one at the desired Item_Id.
Is there another (direct) way to Update the quantity?
You can execute a UPDATE directly:
UPDATE table SET quantity = quantity + 5 WHERE Item_id = <x>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With