insert into table_a@database_a select * from table_a where id not in (select id from table_a.id@database_a)

解决方案 »

  1.   

    写法:
    insert into table_a@database_a 
    select * from table_a where id not in
    (select id from table_a@database_a);
     
    不过这个SQL效率很差,如果数据大的话会很恐怖的
      

  2.   

    insert into table_a@database_a select * from table_a where id not in
    (select id from  table_a@database_a)
      

  3.   

    或:
    insert into table_a@database_a select * from table_a where not exists
    (select id from  table_a@database_a)
      

  4.   

    不过这个SQL效率很差,如果数据大的话会很恐怖的
     还有更加好的方法吗?
      

  5.   


    应该用:
    insert into table_a@database_a select * from table_a where not exists
    (select id from  table_a@database_a)
      

  6.   

    我是尽量避免远程的两个表做关联查询
    你可以将SITE A(或B)上的表做一些过滤,然后全数INSERT到SITE B(A)上的
    某个中间表(temp)去,然后在SITE B用:
    insert into b
    select * from temp where not exist 
    (select 1 from b where b.id=temp.id);最好B表和TEMP表的id上都有索引