Join queries are not working as expected when trying to compare a count result with a value
I would start with:

SELECT course_id
FROM courses_students
GROUP BY course_id
HAVING COUNT(student_id) &gt; 5


The result of this query is a new relation (table, derived table), which you can use as any other table. Let's call this corses_5_students

SELECT c.*
FROM courses as c
JOIN (
    SELECT course_id
    FROM courses_students
    GROUP BY course_id
    HAVING COUNT(student_id) &gt; 5
) AS corses_5_students
    ON corses_5_students.course_id = c.course_id