比如有二個表A,BA:
num | name
-----+------
   1 | a
   2 | b
   3 | cB:
  id | name
-----+------
   1 | a
   1 | b寫一個SQL語句。查詢A表中的name,其條件是B表中id為1,且name的值不在A表name中查詢結果應該是:A:
num | name
-----+------
   3 | c
這個語句怎麼寫呢?50分,thx!

解决方案 »

  1.   

    select * from a
    where  NOT EXISTS (select name from b)這樣寫可以嗎?效率怎樣呢?我想要一個高效率的。
      

  2.   

    A:
    num | name
    -----+------
    3 | c也不符合楼主说的条件阿
      

  3.   

    select * from a where not exists (select name from b where b.id<>1)
    不知是不是你想要的?
      

  4.   

    select * from a where not exists (select name from b where b.id=1)
      

  5.   

    select * from a
    where  NOT EXISTS (select * from b)
    或者
    select * from a
    where name NOT in (select name from b)