有两个表a b  都有一个id字段查询a表 如果a表的id在b表里存在就不查询出来

解决方案 »

  1.   

    有两个表a b  都有一个id字段查询a表 如果a表的id在b表里存在就不查询出来select * from a where id not in (select id from b)
      

  2.   

    select * from a where id not in (select id from b)
      

  3.   

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

  4.   

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

  5.   


    select * from a where id not in (select id from b)--或select a.*
    from a left join b on a.id=b.id
    where b.id is null
      

  6.   

    select * from a where id not in (select id from b)
      

  7.   

    过路的。试问
    select a.* from a where not exists(select 1 from b where id=a.id)

    select * from a where id not in (select id from b)和
    select a.*
    from a left join b on a.id=b.id
    where b.id is null
    的性能
      

  8.   

    有两个表a b  都有一个id字段查询a表 如果a表的id在b表里存在就不查询出来--------------------------select * from a 
    where not exists (select 1 from b where a.id=b.id)
      

  9.   

    peachlee(peachlee) ( ) 信誉:98  2007-09-04 17:20:35  得分: 0  
     
     
       过路的。试问
    select a.* from a where not exists(select 1 from b where id=a.id)

    select * from a where id not in (select id from b)和
    select a.*
    from a left join b on a.id=b.id
    where b.id is null
    的性能
      
    ---------------------
    這個要看表大小怎麼樣,如果 b 表小的話select a.* from a where not exists(select 1 from b where id=a.id)

    select * from a where id not in (select id from b)

    select a.*
    from a left join b on a.id=b.id
    where b.id is null都快,
    如果 b 表大的話select * from a where id not in (select id from b)這個要慢