title: Group by a field not in select
body: <p>I want to find how many modules a lecturer taught in a specific year and want to select name of the lecturer and the number of modules for that lecturer. </p>
  
  <p>Problem is that because I am selecting <code>Name</code>, and I have to group it by name to make it work. But what if there are two lecturers with same name? Then sql will make them one and that would be wrong output. </p>
  
  <p>So what I really want to do is select <code>name</code> but group by <code>id</code>, which sql is not allowing me to do. Is there a way around it?</p>
  
  <p>Below are the tables:</p>
  
  <pre><code>Lecturer(lecturerID, lecturerName)
  Teaches(lecturerID, moduleID, year)
  </code></pre>
  
  <p>This is my query so far:</p>
  
  <pre><code>SELECT l.lecturerName, COUNT(moduleID) AS NumOfModules
  FROM Lecturer l , Teaches t
  WHERE l.lecturerID = t.lecturerID
  AND year = 2011
  GROUP BY l.lecturerName --I want lectureID here, but it doesn't run if I do that
  </code></pre>