insert into A select B.* from A,B where A.id <> B.id
A表B表在同一个数据库中吗,如是直接insert into A select * from B不就可以了!
重新生明一下刚才写的语句不对:以下的语句才是正确的. insert into A select b.* from b where b.id not in (select B.* from A,B where A.id =b.id)
我就是这样用的呀: WITH ADOQUERY DO BEGIN close; sql.Clear; sql.add('INSERT into LS SELECT * from TEMP'); EXECSQL; end; end; 问题是如果LS与TEMP有相同的记录时会出错,而我要求用TEMP中的记录更新LS中相同的记录。
insert into A select b.* from b where b.id not in (select B.id from A,B where A.id =b.id)
可以先把A的记录删除.然后再插入呀 delete a from a,b where a.id=b.id insert into A select b.* from b where b.id in (select B.id from A,B where A.id =b.id)
select B.* from A,B where A.id <> B.id
insert into A
select b.* from b where b.id not in (select B.* from A,B where A.id =b.id)
WITH ADOQUERY DO
BEGIN
close;
sql.Clear;
sql.add('INSERT into LS SELECT * from TEMP');
EXECSQL;
end;
end;
问题是如果LS与TEMP有相同的记录时会出错,而我要求用TEMP中的记录更新LS中相同的记录。
select b.* from b where b.id not in (select B.id from A,B where A.id =b.id)
delete a from a,b where a.id=b.id
insert into A
select b.* from b where b.id in (select B.id from A,B where A.id =b.id)