写法: insert into table_a@database_a select * from table_a where id not in (select id from table_a@database_a);
不过这个SQL效率很差,如果数据大的话会很恐怖的
insert into table_a@database_a select * from table_a where id not in (select id from table_a@database_a)
或: insert into table_a@database_a select * from table_a where not exists (select id from table_a@database_a)
不过这个SQL效率很差,如果数据大的话会很恐怖的 还有更加好的方法吗?
应该用: insert into table_a@database_a select * from table_a where not exists (select id from table_a@database_a)
我是尽量避免远程的两个表做关联查询 你可以将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上都有索引
insert into table_a@database_a
select * from table_a where id not in
(select id from table_a@database_a);
不过这个SQL效率很差,如果数据大的话会很恐怖的
(select id from table_a@database_a)
insert into table_a@database_a select * from table_a where not exists
(select id from table_a@database_a)
还有更加好的方法吗?
应该用:
insert into table_a@database_a select * from table_a where not exists
(select id from table_a@database_a)
你可以将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上都有索引