title: How to 'add' a column to a query result while the query contains aggregate function?
body: <p>I have a table named 'Attendance' which is used to record student attendance time in courses. This table has 4 columns, say 'id', 'course_id', 'attendance_time', and 'student_name'. An example of few records in this table is:</p>
  
  <p>23&nbsp;&nbsp;&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;&nbsp;1/1/2010 10:00:00&nbsp;&nbsp;&nbsp;&nbsp;Tom</p>
  
  <p>24&nbsp;&nbsp;&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;&nbsp;1/1/2010 10:20:00&nbsp;&nbsp;&nbsp;&nbsp;Bob</p>
  
  <p>25&nbsp;&nbsp;&nbsp;&nbsp;187&nbsp;&nbsp;&nbsp;&nbsp;1/2/2010 08:01:01&nbsp;&nbsp;&nbsp;&nbsp;Lisa</p>
  
  <p>.....</p>
  
  <p>I want to create a summary of the latest attendance time for each course. I created a query below:</p>
  
  <pre><code>SELECT course_id, max(attendance_time) FROM attendance GROUP BY course_id
  </code></pre>
  
  <p>The result would be something like this</p>
  
  <p>100&nbsp;&nbsp;&nbsp;&nbsp;1/1/2010 10:20:00</p>
  
  <p>187&nbsp;&nbsp;&nbsp;&nbsp;1/2/2010 08:01:01</p>
  
  <p>Now, all I want to do is add the 'id' column to the result above. How to do it?</p>
  
  <p>I can't just change the command to something like this</p>
  
  <pre><code>SELECT id, course_id, max(attendance_time) FROM attendance GROUP BY id, course_id
  </code></pre>
  
  <p>because it would return all the records as if the aggregate function is not used. Please help me.</p>