title: MySQL update a master field only if condition is true
body: <p>Is there a way to update SQL in such a way, for example.</p>
  <p>Master Table has a column called INVOICESCOUNT.</p>
  <p>When an invoice is deleted successfully, then the INVOICESCOUNT is decreased.</p>
  <p>For example, a SQL psuedo-code statement like this:</p>
  <pre><code>Delete From Invoices where INVOICE=500;
  Update Customers SET INVOICECOUNT=INVOICECOUNT-1 WHERE Customer=1  (if prior statement returns 1 affected row);
  </code></pre>
  <p>I need it to be embedded within the same SQL statement instead of having the source code handling executing the 2 statements separately.</p>
  <p>Thanks for any advice.  Please also let me know if there is any minimal MySQL version requirement if there is such a solution.</p>
  <p>UPDATE with more info:  note that the list of Customers I present to the user can be very different each time, example,  CustomerGroupID=? or CustomerCreated within a certain date, so the Customers query cannot be cached efficiently, as such I prefer to update the INVOICECOUNT (as it will be hit on many times in an hour by different users listing different groups of customers).</p>