试试
select id from a1 where not exists(select * from b1 where b1.id = a1.id)

解决方案 »

  1.   

    这样是没有什么问题。。只不过我想看看select a1.id from a1,b1 where a1.id(+)<>b1.id
    是不是效果等同于:
    select id from a1 where id not in (select id from b1)
      

  2.   

    不等同
    你多举几个例子你就知道区别了
    (+)是外联,你用到的是左外联。如:左外联可以返回一个表中id=null的记录
    而且第二个查询语句效率很低。
      

  3.   

    可用了上面的语句后出来的记录还是有存在与b1中ID相同的记录
    -----
    你那两个语句是不等价的,举个例子
    a1
    id name
    1  a
    2  b
    3  c
    4  d
    a2
    id name
    1  a
    2  b
    按select a1.id from a1,b1 where a1.id(+)<>b1.id
    你会查到
    id
    2
    3
    4
    1
    3
    4
    而按select id from a1 where id not in (select id from b1)
    你会查到
    id
    3
    4
      

  4.   

    不同
     1、a1.id(+)<>b1.id 
     2、id not in (select id from b1) ==>a1.id<>b1.id 
      
     能看出第一个会出现重解的可能,第二个是不会的。
      

  5.   

    试试这个
    select id from a1 where id in( (select a.id from a1 a) minus (select b.id from b1 b))