title: Using WHERE clause in ON DUPLICATE KEY UPDATE column
body: <p>Here's the table design for a cartitems table</p>
  
  <p><strong>cartitems</strong></p>
  
  <pre><code>cartitem_id PK AI
  customer_id FK
  item_id FK UNIQUE 
  item_quantity INT DEFAULT 1
  </code></pre>
  
  <p>What I need to accomplish</p>
  
  <p>1.) if <code>item_id</code> exists in the table, increment the <code>item_quantity</code> by <strong>1</strong> everytime user clicks on "<strong>Add To Cart</strong>" button for the <strong>same</strong> <code>item_id</code></p>
  
  <p>2.) if <code>item_id</code> doesn't yet exist in the table, run an insert statement.</p>
  
  <p>So what I did is this.</p>
  
  <pre><code>CREATE DEFINER=`root`@`localhost` PROCEDURE `addItemToCart`(aCustomerId int, aProductId int)
      BEGIN
          INSERT INTO cart_items(customer_id,product_id) 
          VALUES(aCustomerId,aProductId)
  
          ON DUPLICATE KEY UPDATE
          item_quantity = item_quantity + 1
  
          WHERE customer_id = aCustomerId AND item_id = aProductId;
      END
  </code></pre>
  
  <p>But when I inspected it, I get an error that says, <code>missing semicolon</code> at <code>item_quantity = item_quantity + 1</code></p>
  
  <p>I can't figure out what's causing the error. I don't know if it's a problem with the <code>WHERE</code> clause.</p>
  
  <p>I'd appreciate any help. </p>
  
  <p>Thanks.</p>