我正在努力提供一个从未教过课程部分的教师名单。
首先,我选择教授课程部分的教师名单
SELECT w.COURSE_NO
FROM INSTRUCTOR z , SECTION w
WHERE z.INSTRUCTOR_ID = w.INSTRUCTOR_ID
但是当提供一个从未教过它的列表时,不会给我任何行或错误
SELECT SALUTATION, FIRST_NAME, LAST_NAME,ZIP
FROM INSTRUCTOR,SECTION
WHERE COURSE_NO NOT IN
(SELECT w.COURSE_NO
FROM INSTRUCTOR z , SECTION w
WHERE z.INSTRUCTOR_ID = w.INSTRUCTOR_ID)
ORDER BY SALUTATION, FIRST_NAME, LAST_NAME,ZIP;
我如何提供从未教过的教师名单?
答案 0 :(得分:1)
我认为您忘记将连接谓词放在主要查询中:
SELECT SALUTATION, FIRST_NAME, LAST_NAME,ZIP
FROM INSTRUCTOR a,SECTION b
WHERE a.INSTRUCTOR_ID = b.INSTRUCTOR_ID AND COURSE_NO NOT IN
(SELECT w.COURSE_NO
FROM INSTRUCTOR z , SECTION w
WHERE z.INSTRUCTOR_ID = w.INSTRUCTOR_ID)
ORDER BY SALUTATION, FIRST_NAME, LAST_NAME,ZIP;
尝试使用ANSI-92。
SELECT SALUTATION, FIRST_NAME, LAST_NAME,ZIP
FROM INSTRUCTOR a
INNER JOIN SECTION b ON a.INSTRUCTOR_ID = b.INSTRUCTOR_ID
WHERE COURSE_NO NOT IN
(SELECT w.COURSE_NO
FROM INSTRUCTOR z
INNER JOIN SECTION w ON z.INSTRUCTOR_ID = w.INSTRUCTOR_ID
)
ORDER BY SALUTATION, FIRST_NAME, LAST_NAME,ZIP;