select * from tableB b where not exists (select * from tablea a where b.course_id = a.course_id)
不知道有没理解错楼主的意思

解决方案 »

  1.   

    select student_id,course_id from student
    where course_id in
    (select course_id from student
     minus
     select course_id from course);
      

  2.   

    select distinct B.student_id, A.course_id from A,B
    minus 
    select student_id,course_id from B
    是学生未选课程的记录,楼主是这个意思吗?
      

  3.   

    select b.course_id,b.student_id
    from a ,b
    where b.course_id = a.course_id(+)
    where a.course_id is null
      

  4.   

    frien(friend3355) 说的一点问题也没有,关键的问题是能不能优化一下呢
      

  5.   

    select * from b where not exists (select * from a where b.course_id = a.course_id)
    完全是第一位朋友的想法,我已经试了前通过。
    A表:         B表:
      C1             C1   S1
      C2             C2   S2
      C3             C3   S3
      C4             C4   S4
                     C5   S5
                     C6   S6
    输出结果为:C5   S5
               C6   S6
    不知道满不满足楼主的意思?
      

  6.   

    抱歉,是我没有说明白
    A表:         B表:
      C1             C1   S1
      C2             C2   S2
      C3             C3   S3
      C4             C4   S4输出结果为: C2   S1
                 C3   S1
                  c4   s1
                  c1   s2
                  c3   s2
                  c4   s2
                  ..   ..
                  c1   s4
                  c2   s4
                  c3   s4
      

  7.   

    看看这样行不行:
    select distinct B.student_id, A.course_id from A,B where B.course_id <> A.course_id
      

  8.   

    去掉distinct也可以,select B.student_id, A.course_id from A,B where B.course_id <> A.course_id