title: SQL Server : Group by breaks my program
body: <p>I have the following query. The idea is to inner join the records and group them in order to get one record (the latest one) from each group. </p>
  
  <ul>
  <li>If I add the <code>GROUP BY</code> (like on the example bellow) it doesn't work. </li>
  <li>If I remove the <code>GROUP BY</code> the query works but display duplicated data.</li>
  <li>If I group by all fields that I selected before the inner join, it works but not as intended. It will display all records.</li>
  </ul>
  
  <p>Any suggestions?</p>
  
  <pre><code> SELECT 
      Calibrations.Cert_No, 
      Calibrations.Cust_Ref, 
      Calibrations.Rec_Date, 
      Instruments.Inst_ID, 
      Instruments.Description, 
      Instruments.Model_no, 
      Instruments.Manufacturer, 
      Instruments.Serial_no, 
      Instruments.Status, 
      Instruments.Cust_Acc_No  
   FROM 
      Instruments 
   INNER JOIN 
      Calibrations ON Instruments.Inst_ID = Calibrations.Inst_ID  
   WHERE 
      Instruments.Cust_Name = '" &amp; Session("MM_Username") &amp; "' 
      AND Instruments.Cust_Acc_No = '" &amp; Session("MM_Password") &amp; "' 
      AND Instruments.Cust_Acc_No = '" &amp; Replace(rsDue__MMColParam, "'", "''") &amp; "' 
      AND Instruments.Status IN ('N')
   GROUP BY
      Instruments.Inst_ID  
   ORDER BY 
      Calibrations.Rec_Date DESC
  </code></pre>