表A 
ID TYPE
1   A
2
3   A
4
5
6
7   A
8
0   A
11
表B
ID
4
6
74
4
7
3
4
7
8在A中 查找TYPE为'A'的记录 看其是否完全包括了表B 如果
不包括几把不包括的记录插入A中

把B中不在A中TYPE为'A'的记录插进A中

解决方案 »

  1.   

    insert into a select id , type = '' from b where id not in (select id from a where type = 'A')
      

  2.   

    insert into a select id , type = 'A' from b where id not in (select id from a where type = 'A')
      

  3.   

    INSERT A(ID) SELECT ID FROM B WHERE NOT EXISTS (SELECT 1 FROM A WHERE TYPE='A' AND ID=B.ID)
      

  4.   

    not in 我也想到了
    只是效率太低
    因表A 为母表 10W多条记录
    其有 4 5个子表() 2W多条记录
    其子表每断时间都会新增部分不在母表A中的记录 也就是100条左右
    为了新增这100条记录 10W与1W进行NOT IN 效率太低
      

  5.   


    IF (NOT EXISTS (select b.* from a,b where a.id=b.id and  TYPE='A' ))
    INSERT a select * from b
      

  6.   

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