select c_1,c_2 from t1
where  exists
( select * from t2 where c_3='a' and t1.id=t2.id)
and not exists
(select * from t2 where c_4='b' and t1.id=t2.id)

解决方案 »

  1.   

    select c_1,c_2 from t1
    where id in (
     (select id from t2 where c_3='a')MINUS
    (select id from t3 where c_4='b'))
      

  2.   

    谢谢各位!to  welyngj(平平淡淡) :我也试过你的方法,但是结果好象和我上面所写的select query结果不一样。zlqs(啊啊啊) :我去试试!
      

  3.   

    请问:
    select c_1,c_2 from t1
    where id in 
      (select id from t2 where c_3='a')
    and id in
      (select id from t3 where c_4='a')

    select c_1,c_2 from t1
    where id in
      ((select id from t3 where c_3='a') 
       union
       (select id from t4 where c_4='b'))
    这两个sql语句一样吗?
      

  4.   

    sorry!表名错了。
    这个:
    select c_1,c_2 from t1
    where  exists
    ( select * from t2 where c_3='a' and t1.id=t2.id)
    and not exists
    (select * from t3 where c_4='b' and t1.id=t3.id)