我需要做这样的事情
insert into tableA(code) select code from tableB where id=tableB.id;
我无法插入代码,直到两个id都匹配。我该怎么做?
答案 0 :(得分:1)
您可以加入或使用{/ 1}}
where exists
(OR)
insert into tableA(code)
select tb.code
from tableB tb
join tableA on tableA.id = tableB.id;
查看您的评论,看起来您需要{/ 1}}语句,如
insert into tableA(code)
select tb.code
from tableB tb where exists(select 1 from tableA
where id = tb.id);
答案 1 :(得分:0)
INSERT INTO tableA.field1,tableA.field2,......
SELECT tableB.field1,tableB.field2,......
FROM tableB
JOIN tableA ON tableA.id = tableB.id;