In order to do this, mysql needs to know what to do with other columns. You are GROUP In a column that must be unique, and use a function that will tell it what to do with the rest (the so-called aggregate function ). MAX()and COUNT()are typical examples:
SELECT studentId, COUNT(courseId) AS AmountEnrolledCourses
FROM student_enrollment
GROUP BY studentId
SELECT athlete, MAX(distance) AS PersonalRecord
FROM longjump
GROUP BY athlete
source
share