1.  表A  id....
    表B  id....两表的ID是一样的,查找出A表中不包含B表ID的数据select * from a where id not in (select id from B);
这是我写的,但是他说用Not in效率太低,可否有别的方法,我就答不出来了
2. 表c  
   logID(流水号) id(有重复的id,但是越往下的是越新的)
     1             30
     2             30
     3             31
     4             32
     5             32
     6             33
 查找出所有最新没有重复的id
 结果:  logId    id
          2      30
          3      31
          5      32
    
求教,谢谢

解决方案 »

  1.   

    1.
    select * from a where not exists(select 1 from b where b.id=a.id)
    2.
    select * from c a where not exists(select 1 from c b where a.id=b.id and a.logid<b.logid)
      

  2.   

    1. select a.* from a left join b on a.id=b.id where b.id is null
    2.select * from c as a where logID=(select max(logID) from c  where id=a.id)
      

  3.   

    select * from cbc a where logid>=all(select logid from cbc
    where id=a.id)
      

  4.   


    1、用except
    2、用exists辅助max函数
      

  5.   

    第2个
    select max(logID),id from 表c group by id
    不对吗??
      

  6.   

    1.select * from a left join b on a.id=b.id where b.id is null --這個比較高效.
      

  7.   

    嘿嘿,面试问的很基础哦.多在csdn待着,就能学到知识
      

  8.   

    好吧,这个很基础,看来我是很难找到工作了去年,在一家电子商务网站做了1年PHP,等于是维护,现在出来什么都不会了