表T1:(#depart_id, c_id)
表T2:(#No, c_id, re, date)现在我想找出,表T2的数据,条件是 T2中的c_id不在T1中,请问该怎么写呢?SELECT No, c_id, re, date from T2 where 。怎么写?谢谢

解决方案 »

  1.   

    SELECT No, c_id, re, date from T2 where t2.c_id not in(select t1.c_id  from t1,t2 where t1.c_id=t2.c_id)
      

  2.   

    前提是我不想用in,我只想用exists。
      

  3.   

    SELECT No, c_id, re, date from T2 where exists(select 1 from t1 where t1.c_id =t2.c_id ); 
      

  4.   

    ok
    不存在的改成not exists就行了
      

  5.   

    SELECT No, c_id, re, date from T2 where  not exists(select 1 from t1 where t1.c_id =t2.c_id ); 
      

  6.   

    SELECT No, c_id, re, date from T2 where exists(select 1 from (select c_id from t2 minus select c_id from t1));
    不知道行不
    SELECT No, c_id, re, date from T2 where t2.c_id not in(select t1.c_id  from t1,t2 where t1.c_id=t2.c_id)
    就很好了
      

  7.   

    6楼正解!
    select *
    from T2
    where not exists(
    select 1 
    from T1
    where T1.c_id=T2.c_id