select * from tbname1
where not exists (select 1 from tbname2 where tbname2.id=tbname1.id);

解决方案 »

  1.   

    select * from 表1 where 表1.学号 not in (select 学号 from 表2)
      

  2.   

    select * from table1,table2 where code1=code2(+) and code2 is null;
      

  3.   

    select * from table1,table2 where table1.学号=table2.学号(+) and table2.学号 is null
      

  4.   

    select code from tab1
    minus
    select code from tab2
      

  5.   


     假设学号列为StNo
     select table1.StNo from table1,table2 where 
     (table1.StNo = table2.StNo(+) and table2.StNo is null)
      这条SQL语句的效率明显强于使用NOT IN. minus操作符是区间操作符,例如你要查询 rowum范围为 10-20的
     数据:
      select * from table1 where rownum<=10
      minus
      select * from table1 where rownum<=20
      
      但是,在大数据量时效率比较低.