SQL table1 row_id不显示table2 row_id

时间:2015-05-25 05:46:07

标签: php mysql sql

以下是我的SQL查询

select c.course_id,c.course_title,c.course_credits,c.course_status from       
 course c,(select course_id from completed_course 
 where student_id='1229CSE00241') as a
 where c.course_id!=a.course_id   

但是它显示了所有课程但我只想要课程c  不属于a。

的课程

2 个答案:

答案 0 :(得分:4)

select 
c.course_id,
c.course_title,
c.course_credits,
c.course_status 
from course c 
where 
c.course_id NOT IN (select course_id from completed_course where student_id='1229CSE00241');

答案 1 :(得分:1)

select c.course_id,
c.course_title,
c.course_credits,
c.course_status 
from course c where c.course_id not in 
(select course_id from completed_course where student_id='1229CSE00241')