GROUP BY More Than One Column
Each unique combination of the grouped columns becomes one row.
Example
SELECT c.level, c.title, COUNT(e.student_id) AS enrolled
FROM courses c LEFT JOIN enrolments e ON e.course_id = c.id
GROUP BY c.level, c.title;Result
level | title | enrolled Beginner | CSS Basics | 1 Beginner | Intro to HTML | 2 Beginner | Python | 3 Beginner | SQL | 1 Intermediate | JavaScript | 1
Exercise
Group by a column.
GROUP country
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.