title: Error with 'group by' from joined tables in sql server
body: <p>I have two tables, Table1 with <code>City_Code, name, population</code>, and Table2 with <code>City_Code, Type</code>.
  I need to sum the population by city type, so I use this code:</p>
  
  <pre><code>SELECT SUM(population) FROM Table1 
  JOIN Table2 ON Table2.City_Code = Table1.City_Code
  GROUP BY Table2.Type
  </code></pre>
  
  <p>The resulting table looks like this </p>
  
  <p><img src="https://i.stack.imgur.com/FtQon.png" alt="result"></p>
  
  <p>There are indeed 6 city "Type"s, and the sum is correct, but the figures don't match. I've checked the data with <code>sumif</code> in excel, and the real sum by is actually this:</p>
  
  <p><img src="https://i.stack.imgur.com/JTs4J.png" alt="Excel"></p>
  
  <p>why is the SQL result not in the correct population for type </p>