I have table with following format StoreID | ItemID | ItemName | Qty . StoreID and ItemID are Pkeys.
Im trying to execute mysql query and insert StoreID ='ST1 ' ItemID ='IT1' ItemName='IT' Qty=1000
But here i want to insert the record if not exists, if exists update the Qty = Qty+ 100.
I tried using mysql Replace into and Duplicate key update. It does what i want to do, except Qty not increasing.
Both queries below set Qty to 0 when execute first time. As i can understand thats because there is no duplicate entry at the first time.
What i want to do is add the record if not exists with given qty and update only qty each time it execute afterwards
Joined: Nov 25, 2012
Hi. I got the solution already.
subject: MySQL Replace and DUPLICATE KEY not giving sum of column value