注意:這些不是家庭作業問題。我正在學習dbms,因此這些作業類似的問題。高效SQL查詢
兩個表:
Teachers (teacher_id, teacher_name)
Courses (teacher_id,course_id, course_name)
爲了選擇誰不教任何課程的老師的名字,有 兩個查詢我能想到的:
mysql> explain select teacher_name from teachers left join courses on (teachers.
teacher_id = courses.teacher_id) where course_id is null;
mysql> explain select teacher_name from teachers where teacher_id not in (select
teacher_id from courses);
哪一個會更有效?爲什麼?
您需要將TeacherID添加到課程表中。 – 2009-04-19 04:19:23