title: Subtracting 2 columns from different tables with the same ID
body: <p>I have 2 tables <code>TblAddToInventory</code> and <code>TblWithdrawnFromInventory</code>. Both have <code>ProductID</code> and <code>Quantity</code>. When a withdrawal is made, naturally the Inventory should deduct the quantity of items but only items that have been withdrawn. Example:</p>
  
  <blockquote>
    <p>TblAddToInventory</p>
  </blockquote>
  
  <pre><code>ProductID | Quantity | Amount | Date
  
  1           2          2.00     7/7/2012
  
  2           3          3.00     7/7/2012
  
  3           4          4.00     7/7/2012
  
  2           2          2.00     7/8/2012
  
  3           3          3.00     7/8/2012
  </code></pre>
  
  <blockquote>
    <p>TblWithdrawnFromInventory</p>
  </blockquote>
  
  <pre><code>ProductID | Quantity | Amount | Date
  
  2           4          4.00     7/9/2012
  
  3           5          5.00     7/10/2012
  </code></pre>
  
  <p>With this, when I join the two tables and deduct the specific columns, I should have a <code>DataGridView</code> using C# with this data:</p>
  
  <pre><code>ProductID | Quantity | Amount 
  
  1           2          2.00
  
  2           1          1.00
  
  3           2          2.00
  </code></pre>
  
  <p>I know how to use <code>SUM</code> and <code>JOIN</code> but I just don't know how to create a syntax that will subtract two columns from different tables with the same ID. </p>
  
  <p>I don't know if this is the right way but what I have in mind is <code>SUM</code> all from <code>TblAddToInventory</code> using <code>GROUP BY</code> then <code>SUM</code> all from <code>TblWithdrawnFromInventory</code> using <code>GROUP BY</code> and then <code>SUBTRACT</code> columns from <code>TblAddToInventory</code> and <code>TblWithdrawnFromInventory</code> using <code>GROUP BY</code>. But I don't think that's a good idea. Can you help? </p>
  
  <p>Thank you.</p>