【问题标题】:Select multiple values from one table1, find in table2 and insert in table3从一个table1中选择多个值,在table2中查找并在table3中插入
【发布时间】:2019-04-09 07:55:39
【问题描述】:

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

我知道如何向其他表插入行,但我不知道如何选择多个值并使用多个值。

【问题讨论】:

    标签: sql ms-access vba


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

      使用INSERT INTO 声明:

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

      这仅在 table2 和 table3 具有具有相同对应数据类型的确切列数时才有效。

      【讨论】:

        猜你喜欢
        • 2019-05-22
        • 1970-01-01
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-28
        • 1970-01-01
        相关资源
        最近更新 更多