I have 2 tables:
- courses: a list of open courses
- student_courses: students who have signed up for a course
Tey are described below:
courses:
id
name
approved_by
student_courses:
id
student_id
course_id
paid
I want to list all courses with the following for each course: course id and the number of students signed up for that course. I've tried things like:
SELECT courses.id, SUM(student_courses.id)
FROM courses as courses
LEFT JOIN student_courses as student_courses on student_courses.course_id=courses.id
WHERE courses.approved_by != '0'
But that is only returning 1 row.
GROUP BYclause, needed for the aggregateSUM().