A表 结构如下
  字段: 
   数据类型: id int
            girl varchar   
              women varchar
            birth datetime
            is_valid bit
    id girl      birth     is_valid 
    1  张琳       12-19        1
    2  王娟娟     12-11       1
    3  丁蝶儿     12-12       1
    4  张玉       12-21       1
    5  王婷婷     12-11       1B表 结构如下
  字段: 
   数据类型: id int
            girl varchar   
            women varchar
            birth datetime
            is_valid bit    id girl      birth     is_valid 
    1  张琳       12-19       1
    2  丁蝶儿     12-12       1
    3  张玉       12-21       1请问关联两张表,列出B表没有的内容的SQL语句是什么
     
    id girl      birth     is_valid 
    2  王娟娟     12-11       1
    5  王婷婷     12-11       1请用最高效率的SQL。
谢谢了!

解决方案 »

  1.   

    select *
    from tablea 
    where girl not in(select girl from talbeb)
      

  2.   

    select * 
    from table
    where not exists(select 1 from tableb)
      

  3.   

    更正一下select * 
    from tablea
    where not exists(select 1 from tableb where girl = tablea.girl)
      

  4.   

    请用最高效率的SQL。 ====这与索引有关
      

  5.   

    请用最高效率的SQL。   ====select * 
    from tablea
    where not exists(select 1 from tableb where girl = tablea.girl)
      

  6.   

    --比较稳定,效率不随数量浮动大的语句(这里指与not exists或not in比较.数据量大了当然会慢)
    SELECT a.* FROM ta a
    LEFT JOIN tb b
    ON a.girl=b.girl
    WHERE b.girl IS NULL--依具匹配度,匹配度越高,效率越高
    SELECT * FROM ta a
    WHERE NOT EXISTS(SELECT 1 FROM tb WHERE girl=a.girl)--匹配率越低,效率越高
    SELECT * FROM ta WHERE girl NOT IN(SELECT girl FROM tb)--以上的语句的结果,可能会有不一致,排除girl本身为null的情况
      

  7.   

    如果没索引 ,not exists 和 not in 好像全是表级的,似乎效率差不多了
      

  8.   

    ---2005可用
    select * from a
    except
    select * from b 
      

  9.   

    2000:select * from a where checksum(*) not in(select checksum(*) from b )----
    以上方法A表的所有字段都与B表相同时可以(以上的*可用列名(col1,col2...))
      

  10.   

    select * from A
    where not exists(select * from A inner join B on A.id=B.id)
      

  11.   

    ---
    select * from a where checksum(girl,birth ,is_valid) not in(select checksum(girl,birth ,is_valid) from b)