Join queries are not working as expected when trying to compare a count result with a value I'm learning SQL from a book and I'm trying to do some exercices on join queries. The only problem that I'm facing is that all of my join queries are not working while they seem well.

These are the tables:

    students(student_id,student_names,student_age)
    courses_students(course_id,student_id)
    courses(course_id,course_schedule,course_room,teacher_id)
    teachers(teacher_id,teacher_names)


The query is "which courses have more than 5 students enrolled?"

Here is what I've done:

select 
  course_name,
  count(select count(*) from courses) as count 
from students,courses,courses_students 
where students.student_id = courses_students.student_id,
courses.course_id = courses_students.course_id 
and count &gt; 5


And the other one is "what are the names of students enrolled in at least 2 courses scheduled for the same hours?"

My query:

select student_name,schedule 
from students,courses,courses_students 
where students.student_id = courses_students.student_id,
courses.course_id = courses_students.course_id 
and count &gt; 2
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