我想返回一個在一個部門上課但不在另一個部門上的學生列表。這是我的查詢,由於某種原因,其結果是空白。如何查詢一個不包含MySQL中另一個集合中的任何成員的集合?
SELECT *
FROM student
JOIN transcript
ON student.id = transcript.studID
JOIN course
ON transcript.crsCode = course.crsCode
WHERE deptId = "CSCI" NOT IN
(
SELECT student.name
FROM student
JOIN transcript
ON student.id = transcript.studID
JOIN course
ON transcript.crsCode = course.crsCode
WHERE deptId = "MATH"
);
這裏是什麼表是這樣的:
Student (id, name, address, status)
Transcript (studId, crsCode, semester, grade)
Courses (crsCode, deptId, crsName, descr)
例如http://forums.mysql.com/read.php?10507748,507839 – Strawberry