Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL Replace and DUPLICATE KEY not giving sum of column value

 
rayan alex
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
rayan alex
Ranch Hand
Posts: 33
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I got the solution already.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic