title: SQL query, NOT EXISTS
body: <p>Hi I am evaluating a SQL query with the following schema:<br>
  Student(<strong>sid</strong>, name, age, gender, dept, GPA) <br>
  Faculty(<strong>fid</strong>, name, age, office, dept) <br>
  Course(<strong>cid</strong>, name, description) <br>
  Teach(<strong>fid</strong>, <strong>cid</strong>, term) <br>
  Enrollment(<strong>sid</strong>, <strong>cid</strong>, term, grade, final grade)<br><br>
  The question to base query on is: <br>
  Find the students who took at least one course with Tom<br><br>
  The query looks like: <br></p>
  
  <pre><code>SELECT *
  FROM Student S1
  WHERE NOT EXISTS (SELECT E1.cid
                    FROM Enrolment E1, Student S2
                    WHERE E1.sid = S2.sid 
                          AND S2.name = 'Tom'
                    MINUS
                    SELECT E2.Cid
                    FROM   E2 Enrollment
                    WHERE  E2.sid = S1.sid)
  </code></pre>
  
  <p>This query is not making sense to me because to me it seems like the NOT EXISTS condition would only select a student when the subquery is empty, and this would only occur in the case when student s1 has taken all the same courses as Tom. However the question is to find the students who took at least one course, not all courses as Tom. Maybe I am interpreting wrong but I could use some clarification.</p>