就是将a表有的数据但b表没有的数据插入到b表
insert into b select * from a where id not in(select id from b) 
请问 这在SQL  上有更好的优化吗?在线等  急~~!!!!

解决方案 »

  1.   

    試試這個insert into b select A.* from a left Join b On a.id = b.id Where b.id is null
      

  2.   

    insert into b 
    select * from a 
    where not exists(select 1 from b where b.id=a.id)在b.id上建索引
      

  3.   

    insert into b
    select * from a as tmp
    where not exists(select 1 from b where id=tmp.id)
      

  4.   

    同意paoluo(一天到晚游泳的鱼)的想法,这个通过左连接的一般比not in与not exists效率高,但是如果想下率更高,可以在gahade(与君共勉) 所有的方式建立索引,两个表的id都建立索引,然后用paoluo(一天到晚游泳的鱼)的:insert into b select A.* from a left Join b On a.id = b.id Where b.id is null
      

  5.   

    左连接的一般比not in与not exists效率高??
      

  6.   

    insert into b select a.* from a where a.id not in(select distinct b.id from b)
      

  7.   

    左连接的一般比not in与not exists效率高??我不同意这种说法,exists 通常比 in  / like 更快.
    最好用exists 再在ID上建索引
      

  8.   

    同意free_pop2k() ( )的说法
      

  9.   

    insert into b 
    select * from a as t where t.num not in(select num from b )
      

  10.   

    marco08(天道酬勤)不信你就试试看咯......你的水平应该比较高,试以下咯
    对了,感觉你这人脾气不好。.......