从一个table1中选择多个值,在table2中查找并在table3中插入

问题描述 投票:0回答:2

有table1 table2,table3。在table1中需要选择列Order_ID值= 1的所有列Spec_ID值然后,在table2 Order_ID中选择所有Order_IDfind并将具有该ID的所有行复制到table3。

我知道如何将行插入另一个表,但我无法弄清楚如何选择多个值并使用多个值。

sql ms-access access-vba
2个回答
0
投票

使用INSERT INTO声明:

insert into table3
select * from table2 
where order_id in (select order_id from table1 where spec_id = 1)

仅当table2和table3具有具有相同对应数据类型的确切列数时,此方法才有效。


1
投票

这不是VBA的工作,而是Append查询。

创建一个连接table1和table2的查询,具有您需要的条件,并显示您需要复制的所有列。

然后将查询更改为Append查询,并将其插入table3。

如有必要,可以使用VBA设置查询的参数,请参阅How do I use parameters in VBA in the different contexts in Microsoft Access?

© www.soinside.com 2019 - 2024. All rights reserved.