0

我有一个表,比如说,table2,它与父表 table1 相连。我还有table3,我想将它的内容复制到连接到table1的table2中。Table3 的外键列中可能有一些在 table1 中不可用的值,当我尝试复制这些值时会导致错误。我怎样才能解决这个问题,以便只复制在父表中有引用的记录??

4

2 回答 2

1
Insert into Table2 (<columnList>)
Select <columnlist> 
From Table3 Inner join Table1
On Table3.fieldFromTable3 = Table1.ReferredFieldFromTable1

根据需要使用列,并在 Join 中提供适当的字段名称。

于 2012-07-20T13:59:00.293 回答
0
insert into table2 (col1, col2, ...)
select col1, col2, ... from table3
where table3.refcol in (select keycol from table1)

当然,您需要用实际的列名替换样本。:-)

于 2012-07-20T13:54:06.910 回答