title: I'm getting 'Column name is invalid in the select list' error when i execute the query
body: <p>This is my query,</p>
  
  <pre><code>SELECT TOP (3) 
      a.INCIDENT_ID, a.REFERENCE, SUM(b.COST) AS TOTAL_COST
  FROM          
      FDDC_T_D_INCIDENT AS a 
  INNER JOIN
      FDDC_T_D_INCIDENT_COST AS b ON a.INCIDENT_ID = b.FINCIDENT_ID
  WHERE        
      (a.CREATED_DATE &gt;= @date1) AND (a.CREATED_DATE &lt;= @date2)
  GROUP BY 
      a.INCIDENT_ID
  ORDER BY 
      TOTAL_COST DESC
  </code></pre>
  
  <p>I'm getting an error</p>
  
  <blockquote>
    <p>Column 'FDDC_T_D_INCIDENT.REFERENCE' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</p>
  </blockquote>
  
  <p>Can someone please help me with this issue?</p>
  
  <p>Thanks in advance! </p>