有2个表,一个是学生表,一个是选修历史的学生表,
选择没有选修历史的学生名单,这个怎么写?
谢谢!1.students
index   name 。。
   1     小王  ........
   2     小李  ........
2.class
index       students.index
1                1
2                5

解决方案 »

  1.   

    试试:
    select index from student except select index from class 
      

  2.   

    select a.name from students a where not exists (select b.students.index from class b where a.index=b.index) ;
      

  3.   

    我把except改成not in 就可以了,谢谢!!
      

  4.   

    except 是差集的意思,随手写出来的没想到mysql不认它..
      

  5.   

    select
      name
    from
      students 
    where
      not exists(select 1 from class where `students.index`=students.index and 课程='历史')