SELECT a.*, b.numOfTakingExams
FROM employeeExam a
INNER JOIN
(
SELECT employee_id,
MAX(date) max_Date,
COUNT(*) numOfTakingExams
FROM employeeExam
GROUP BY course_ID, employee_id
) b ON a.employee_id = b.employee_id AND
a.date = b.max_Date
puoi anche ottenere l'ultimo record con il massimo ID
se è impostato come AUTO_INCREMENT
, questa query di seguito restituisce lo stesso risultato della query precedente,
SELECT a.*, b.numOfTakingExams
FROM employeeExam a
INNER JOIN
(
SELECT employee_id,
MAX(id) max_Date,
COUNT(*) numOfTakingExams
FROM employeeExam
GROUP BY course_ID, employee_id
) b ON a.employee_id = b.employee_id AND
a.id = b.max_Date