title: Removing duplicates from the left table
body: <p>I looked at some examples online, unfortunately didn't find a solution.</p>
  
  <p>I have data like this.</p>
  
  <p><strong>Table A</strong></p>
  
  <pre><code>TaskName Pattern
  123      Did not find A
  124      Did not find B
  </code></pre>
  
  <p>And data patterns are generated in this <strong>Table B</strong></p>
  
  <pre><code>VariantId LocalVariantId Pattern
  345       222            Did not find A
  345       223            Did not find A
  345       224            &lt;Something else&gt;
  346       234            Did not find A
  </code></pre>
  
  <p><strong>Table C</strong></p>
  
  <pre><code>VariantId ParseRange
  345       100
  345       200
  346       50
  </code></pre>
  
  <p>I need to combine the data from the three tables to generate data like this</p>
  
  <pre><code>TaskName ParseRange
  123      250 
  </code></pre>
  
  <p><code>250</code> is the sum of <code>max(345) + max(346) = 200 + 50</code></p>
  
  <p>I have the query written, but the problem is duplicates in <code>Table B</code>.</p>
  
  <p>From <code>Table C</code>, I do</p>
  
  <pre><code>select max(ParseRange) from TableC group by VariantId
  </code></pre>
  
  <p>So that gives me <code>200</code> (for <code>VariantId=345</code>)</p>
  
  <p>However when I join that with <code>Table B</code>, unless I do 
      <code>group by TableB.VariantId</code>, 
  I get the duplicates, so the result sum is not the same as <code>250</code>.</p>
  
  <p>Here is something like the query I have</p>
  
  <pre><code>SELECT
      TaskName
      , SUM(TC.ParseRange)
  FROM
      TableB
      JOIN
      (
          SELECT
              VariantId
              , MAX(ParseRange)
          FROM TableC
          GROUP BY VariantId
      ) AS TC ON TableB.VariantId = TC.VariantId
      -- also join with table A on Pattern
  GROUP BY TaskName
  </code></pre>