aspose file tools*
The moose likes JDBC and the fly likes MySQL Replace and DUPLICATE KEY not giving sum of column value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL Replace and DUPLICATE KEY not giving sum of column value" Watch "MySQL Replace and DUPLICATE KEY not giving sum of column value" New topic
Author

MySQL Replace and DUPLICATE KEY not giving sum of column value

rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1
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

Joined: Nov 25, 2012
Posts: 33
    
    1
Hi. I got the solution already.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySQL Replace and DUPLICATE KEY not giving sum of column value