Properly using Not In clause
<p>Here, the scenario is:</p>

<p>I have 4 tables </p>

<ol>
<li><code>Course</code> </li>
<li><code>Student</code></li>
<li><code>Department</code></li>
<li><code>EnrollCourse</code></li>
</ol>

<p>While a student going to enroll a course a list of courses should be in dropdown from courses table. But course_id which are already in enroll_courses table shouldn't load in that courses dropdown. Because a student can't register single course 2 times. Here I'm using <code>not in</code> operation which will retrieve list of course_id which are not in enroll_courses table.</p>

<p>But I'm getting following error for the query:</p>

<blockquote>
  <p>You have an error in your SQL syntax; check the manual that
  corresponds to your MariaDB server version for the right syntax to use
  near 'enroll_courses.course_id LIMIT 0, 25' at line 6</p>
</blockquote>

<p>Here is query:</p>

<pre><code>SELECT students.name, students.email,departments.name as d_name,
        courses.name as c_name
        FROM students JOIN departments on students.department_id=departments.id 
        JOIN courses on departments.id = courses.department_id
        LEFT JOIN enroll_courses on enroll_courses.course_id=courses.id 
        WHERE courses.id NOT IN (enroll_courses.course_id) AND students.id=8
</code></pre>

<p>Anyone who can help me to find the solution?</p>