【问题标题】:Change the row if the primary key is inside second table如果主键在第二个表内,则更改行
【发布时间】:2021-05-02 08:10:26
【问题描述】:

如果 order_no 在今天发货的表中,我想使用 sql 在查询中将订单状态更改为发货。 (我使用 ms 访问)

【问题讨论】:

    标签: sql database ms-access


    【解决方案1】:

    您可以使用where 子句。例如:

    update orders
        set State = 'shipped'
        where order_no in (select ts.order_no from todayshipped as ts);
    

    您可能需要添加 and State <> 'shipped' 以避免更新已发送的行。

    出于性能原因,我经常建议使用exists:

    update orders
        set State = 'shipped'
        where exists (select 1
                      from todayshipped as ts
                      where ts.order_no = orders.order_no 
                     );
    

    这可以轻松利用todayshipped(order_no) 上的索引。

    【讨论】:

    • @NasrullahRslan 。 . .如果这回答了您的问题,您可以接受答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多