title: count number of rows and get only the last row from a table
body: <p>I have a table called <code>employeexam</code> which structure and data are like this:</p>
  
  <pre><code>--------------------------------------------------------
  | id | course_id   | employee_id | degree | date
  --------------------------------------------------------
  | 1  |  1          | 3           | 8      | 2013-01-14
  | 2  |  2          | 4           | 15     | 2013-01-14
  | 3  |  2          | 4           | 17     | 2013-01-15
  --------------------------------------------------------
  </code></pre>
  
  <p>Desired result would be:</p>
  
  <pre><code>---------------------------------------------------------------------------
  | id | course_id   | employee_id | degree | date        | numOfTakingExams 
  ---------------------------------------------------------------------------
  | 1  |  1          | 3           | 8      | 2013-01-14  | 1
  | 3  |  2          | 4           | 17     | 2013-01-15  | 2
  ---------------------------------------------------------------------------
  </code></pre>
  
  <p>My MySQL query:</p>
  
  <pre><code>SELECT DISTINCT(employeexam.employee_id) as employeeid, 
                  employeexam.*, 
                  exam.numOfTakingExams 
       FROM employeexam
       JOIN (
              SELECT employee_id , COUNT(employee_id ) as numOfTakingExams 
              FROM employeexam  
              GROUP BY employee_id
            ) exam
       ON exam.employee_id  = employeexam.employee_id 
       ORDER BY employeexam.id DESC   
  </code></pre>
  
  <p>This outputs <code>numOfTakingExams</code> value correctly, but i can't select only the data of the last time he entered an exam. Any help?</p>