title: MYSQL query involving 'not exists'
body: <p>I have a university practical next week on databases. I need to create 15 queries around a scheme on a university, which looks as follows:</p>
  
  <ul>
  <li>Student(Student_No, First_Name , Last_Name, Sex, Date-Of-Birth, Address, Level,  Degree_Code)</li>
  <li>Degree(Degree_Code, Degree_Name, School_Name)</li>
  <li>Module(Module_Code, Module_Title, School_Name)</li>
  <li>School(School_Name, Faculty, Head-of-School)</li>
  <li>Take_Exam(Student_No, Module_Code, Mark)</li>
  </ul>
  
  <p>I have completed 14 of the queries but I am stuck on this one:</p>
  
  <ul>
  <li>Retrieve the names of students who take every Module.  (Hint. use not exists).</li>
  </ul>
  
  <p>I have been reading up on not exists queries, but I just don't even know where to start!
  I created this piece of code:</p>
  
  <pre><code>select students.student_no, fname, lname, count(module_code)
  from students left join take_exam using (student_no)
  group by student_no
  having count(module_code) &lt; 19
  order by lname;
  </code></pre>
  
  <p>This returns all students who DON'T take all 19 modules. However, I hate the code as it involves having &lt; 19, which meant if the amount of modules ever changed later, this value would need changes which is inefficient.</p>
  
  <p>Can anyone point me in the right direction and give me some guidance on using 'not exists' queries?</p>
  
  <p>Thanks, Andrew</p>