title: SQL query to combine duplicates and sum
body: <p><strong>UPDATE</strong>: <em>sorry for the confusion. "table" was not my actual tablename, I have updated it with the correct name and also more info about the error below.</em></p>
  
  <p>I have a table called TrackingNumbers with two columns. The orderid column data sometimes repeats as there are multiple shipments per order (I didn't design the database): </p>
  
  <pre><code>orderid shipment_cost
  1021    5.34
  1021    7.83
  1022    5.19
  1023    5.59
  </code></pre>
  
  <p>How can I add all the shipment_cost values when the orderid repeats using a SQL query? So I would like the query results to look like:</p>
  
  <pre><code>orderid shipment_cost
  1021    13.17
  1022    5.19
  1023    5.59
  </code></pre>
  
  <p>My best guess is that it goes something like this:</p>
  
  <pre><code>SELECT orderid, SUM(shipment_cost) FROM TrackingNumbers GROUP BY orderid
  </code></pre>
  
  <p>But that gives me an unspecified SQL error. Unsure if it is my query or the silly proprietary app. Thanks for any advice!</p>
  
  <hr>
  
  <p><strong>UPDATE 2:</strong> So it appears my query was OK according to the answers and I also just double-checked on my own MySQL server, comes back OK. It must be the application's fault (Volusion). They have a crappy little interface for running custom reports and it appears to be wrapping my SQL query with extra stuff. The error from Volusion: </p>
  
  <pre><code>SQL Error: SELECT * ,17041 as RecordCount 
             FROM (SELECT TOP 10 * 
                   FROM (SELECT TOP 10 orderid, SUM(shipment_cost) 
                         FROM TrackingNumbers 
                         GROUP BY orderid ORDER BY ) 
                   SUBSEL ORDER BY ) 
             PAGESEL ORDER BY
  </code></pre>
  
  <p>And if I add an ORDER BY like </p>
  
  <pre><code>SELECT orderid, SUM(shipment_cost) 
  FROM TrackingNumbers 
  GROUP BY orderid 
  ORDER BY orderid ASC 
  </code></pre>
  
  <p>since that's what it seems it wants:</p>
  
  <pre><code>SQL Error: SELECT * ,17041 as RecordCount 
             FROM (SELECT TOP 10 * 
                   FROM (SELECT TOP 10 orderid, SUM(shipment_cost) 
                         FROM TrackingNumbers 
                         GROUP BY orderid 
                         ORDER BY orderid ASC) 
                   SUBSEL ORDER BY orderid DESC ) 
             PAGESEL ORDER BY orderid ASC
  </code></pre>
  
  <p>Guess I will have to see if Volusion's support can provide any clues. Thanks again!</p>
  
  <hr>
  
  <p><strong>Update3:</strong> Of course Volusion support is unhelpful even though I told them this query works on another SQL server and it's obvious their interface is mangling it. Looks like I will have to import the data into my down database and manipulate it there.</p>