This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure 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
  • 0
  • 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
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I got the solution already.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic