title: SQL Server-- join tables and SUM columns for each distinct row
body: <p>Could someone double check my SQL statement for proper operation and general commonsense approach?  </p>
  
  <p>Here's what's going on:  I have a parent and child table with a one-to-many relationship, joined on a column named AccountNumberKey.  The child table has numeric columns in it I need to sum up.</p>
  
  <p>The data is such that all child records with a given AccountNumberKey value will always have the same values in their two numeric columns.  I want to join these tables and for 
  each AccountNumberKey put the sum of those two columns into a temp table.  I only need to sum the columns from a single child record given each AccountNumberKey.</p>
  
  <p>Some sample data below will (I hope) make this clearer:</p>
  
  <pre><code>Parent Table Columns
  
  
  ParentID    InstitutionID    AccountNumberKey  
  
  1       LocalHost            1873283  
  2       Acme Brokers         3627389    
  3       Dewey, Cheatem       1392876
  4       NCC1701              8837273
  5       Peyton Place         9981273
  
  
  Child Table Columns
  
  
  ChildID     AccountNumberKey    Value1      Value2       ProposalNumber
  1               1873283         1000        100         58
  2               1873283         1000        100         59
  3               1873283         1000        100         60
  4               1873283         1000        100         61
  </code></pre>
  
  <p>Here's my SQL Statement:</p>
  
  <pre><code>    SELECT   DISTINCT  Parent.InstitutionID, AccountNumberKey, SUM(Child.Value1 + Child.Value2) as total
          INTO   #TempTable
          FROM         Parent 
              INNER JOIN
                Child ON Parent.AccountNumberKey = Child.AccountNumberKey 
  
          GROUP BY Parent.InstitutionID, Parent.AccountNumberKey, Child.ProposalNumber
  </code></pre>
  
  <p>The goal is to link the tables and put data into a temp table so it looks like so:</p>
  
  <pre><code>TempTable columns
  
  
  InstitutionID       AccountNumberKey        Total
  LocalHost           1873283             1100
  </code></pre>
  
  <p>Does my SQL query pass muster?  I'm no genius when it comes to groupings and wondered if this is A) correct and B) an ok way to go or if there are better joins to try.  </p>
  
  <p>Thanks!</p>