title: How to sum values of two matched tables without getting duplicates in SQL
body: <p><img src="https://i.stack.imgur.com/ZuAHT.png" alt="enter image description here"></p>
  
  <p>I got above result in Excel after filtering two tables by (where) <code>tableA.cost = TableB.total</code>.</p>
  
  <p>I tried to apply the same in SQL, but I got duplicate values.</p>
  
  <p>Here is my SQL query:</p>
  
  <pre><code>SELECT sum(total), sum(cost)
  FROM TableA
  INNER JOIN TableB ON tableA.ID = tableB.ClientID
  WHERE tableA.ID = 45454
    AND TableA.code= 'A'
    AND TableA.period = 1
    AND TableB.status = 71
    AND TableA.SORT = 'SS'
    AND TableB.SORT= 'SS'
  </code></pre>
  
  <p>and the result was </p>
  
  <pre><code>total   cost
  -235.80 -47.16
  </code></pre>
  
  <p>So the <code>total</code> column was <em>duplicated five times</em> based on the row numbers in <code>cost</code> column.</p>
  
  <p>Is there any way to prevent total column being <del>not</del> duplicate ?</p>