title: A conditional SQL update statement for two tables at once
body: <p>I want to update two tables at once. The code below seems to work fine. However, in some cases, there is no entry in bidGroups which means the entire statement would fail. How can I adjust it so it updates the first bit (watchedItems) and does not try the second part if watchedItems.bidGroupID IS NULL</p>
  
  <pre><code>UPDATE watchedItems, bidGroups 
  SET watchedItems.won=1, bidGroups.bidGroupQty=bidGroups.bidGroupQty-1 
  WHERE watchedItems.id=2 
  AND watchedItems.aid=200618152822 
  AND bidGroups.bidGroupID=watchedItems.bidGroupID 
  AND bidGroups.id=2;
  </code></pre>
  
  <p>I tried this, but the syntax is wrong..</p>
  
  <pre><code>UPDATE  watchedItems, bidGroups 
  SET watchedItems.won=1, 
  CASE WHEN watchedItems.bidGroupID IS NOT NULL THEN bidGroups.bidGroupQty=bidGroups.bidGroupQty-1 
  ELSE END
  WHERE watchedItems.id=2 
  AND watchedItems.aid=200618152822 
  AND bidGroups.bidGroupID=watchedItems.bidGroupID 
  AND bidGroups.id=2
  </code></pre>