title: How to include other grouped columns
body: <p>I'm joining a couple of tables, and aggregating some of the columns via GROUP BY. This is what I've done with MySQL, now I'm porting them to MSSQL.</p>
  
  <p>A simple example would be employees and projects:</p>
  
  <pre><code>select empID, fname, lname, title, dept, count(projectID)
  from employees E left join projects P on E.empID = P.projLeader
  group by empID
  </code></pre>
  
  <p>...that would work in MySQL, but MS SQL is stricter and requires that everything is either enclosed in an aggregate function or is part of the GROUP BY clause.</p>
  
  <p>So, of course, in this simple example, I assume I could just include the extra columns in the group by clause.  But the actual query I'm dealing with is pretty complicated, and includes a bunch of operations performed on some of the non-aggregated columns... i.e., it would get REALLY ugly to try to include all of them in the group by clause.</p>
  
  <p>So is there a better way to do this?</p>