title: Howto merge into a database
body: <p>I am having trouble figuring out the best way to approach this problem,</p>
  
  <blockquote>
    <p>I have two different list of items,
    one in the DB, one not. Both list have
    item ids and quantity, I need to merge
    the two list into the DB.</p>
  </blockquote>
  
  <p>My first inclination is to just pull all of the items out of the DB then merge the two list in the application logic. I would then delete the old list from the DB and insert the new merged list.</p>
  
  <p>I figure I could also update/inserts for each of the items I want to merge into the DB, however this would mean many queries (maybe there is a stored procedure I could write, but i am not that hot with stored procedures).</p>
  
  <p>I would like to know if SQL or application logic will perform better in this situation?</p>
  
  <p>I would also like to hear how others would tackle this problem.</p>
  
  <p>thanks.</p>
  
  <p>UPDATE:</p>
  
  <p>Here are some more details,</p>
  
  <p>This is not a one time merge, it will happen several times. Basically I have an object in my application that holds a list of items, eventually these items need to be put into the DB. There is already items in the DB, so I can not just insert the items, I must increase the quantity of an item in the DB if two items have the same id and insert items with unique ids.</p>
  
  <p>ONE MORE UPDATE:</p>
  
  <p>using MySQL and PHP</p>