select a.a,a.b from (
select rowid num,t.* from table11 t where t.a in (select distinct f.a from table22 f where f.a=t.a)) a,(
select rowid num,t.* from table11 t where t.b not in (select distinct f.b from table22 f where f.a=t.a))b
where a.num=b.num
这样写可以么?

解决方案 »

  1.   

    select a,b from table11
    where a in (select distinct a from table22)
    and b not in (select distinct b from table22)
      

  2.   

    select * from table11 t1
    where exists(select 1 from table22 t2 where t1.a = t2.a)
    and not exists(select 1 from table22 t3 where t1.b != t3.b)
      

  3.   

    同意duanzilin(寻)的用法,建议在写sql的时候,用exists,不太推荐使用in,如果数据量大就更是了。
      

  4.   

    duanzilin(寻)多了个不等号,
    select * from table11 t1
    where exists(select 1 from table22 t2 where t1.a = t2.a)
    and not exists(select 1 from table22 t3 where t1.b = t3.b)