系统环境:W2k+SQL2000
表A:Name,Age,Time
表B:Name,Tel,Age,Score,Bg,Address
表A有10万记录,表B有上百万记录,均以Name,Age两字段标识唯一记录。
现要查出表A中还没录入表B的记录,这SQL该怎么写?

解决方案 »

  1.   


    select * from A
    where exists (select 1 from b where a.name<>b.name and a.age<>b.age)
      

  2.   

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

  3.   

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

  4.   

    select * from a 
    where not exists(select 1 from b where a.name=b.name and a.age=b.age)
    不知道是不是最高效的
      

  5.   

    SQL 2005:
    select name,age from a
    except
    select name,age from b
      

  6.   

    select
                    * 
              from a 
                    left join b 
                        on a.name=b.name
              where b.name is null             
      

  7.   


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

  8.   

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

  9.   

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

  10.   


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

  11.   

    不理解except关键字 关注下
      

  12.   


    select * from b 
        where not exists(select 1 from a where a.name=b.name and a.age=b.age)不要搞反了A、B的顺序