title: Update using Distinct SUM
body: <p>I have found a few good resources that show I should be able to merge a select query with an update, but I just can't get my head around of the correct formatting.</p>
  
  <p>I have a select statement that is getting info for me, and I want to pretty much use those results to Update an account table that matches the <code>accountID</code> in the select query.</p>
  
  <p>Here is the select statement:</p>
  
  <pre><code>SELECT DISTINCT SUM(b.workers)*tt.mealTax as MealCost,b.townID,b.accountID
  FROM buildings AS b
  INNER JOIN town_tax AS tt ON tt.townID = b.townID
  GROUP BY b.townID,b.accountID
  </code></pre>
  
  <p>So in short I want the above query to be merged with:</p>
  
  <pre><code>UPDATE accounts AS a
  SET a.wealth = a.wealth - MealCost
  </code></pre>
  
  <p>Where <code>MealCost</code> is the result from the select query.  I am sure there is a way to put this into one, I just haven't quite been able to connect the dots to get it to run consistently without separating into two queries.</p>