title: Can I include a non-aggregated Column in an aggregate function in SQL without putting it into a GROUP BY clause?
body: <p>Take the following tables...</p>
  
  <pre><code>Classes
  ClassId ClassName
  1       Math
  2       Math
  3       Science
  4       Music
  
  Registrations
  RegistrationId ClassId StudentName
  1              1       Stu
  2              1       Rick
  3              2       John
  4              4       Barb
  5              4       Dan
  6              3       Einstein
  </code></pre>
  
  <p>Yes, there are 2 classes with the same name (Math) as they may be at different times.  I would like to get a list of the classes and the number of students registered for each one.  I would like the following columns (ClassId, ClassName, StudentCount).</p>
  
  <p>My attempt at this would be something along the lines of...</p>
  
  <pre><code>SELECT Classes.ClassId, Classes.ClassName, Count(Registrations.RegistrationId)
  FROM Classes
  INNER JOIN Registrations ON Classes.ClassId = Registrations.ClassId
  GROUP BY Classes.ClassId
  </code></pre>
  
  <p>(Note I would like to GroupBy the ClassId but NOT ClassName).  Is this possible in SQLServer 2008?  Obviously I ask because SQL complains</p>
  
  <pre><code>"ClassName is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
  </code></pre>
  
  <p>Thanks!</p>