【问题标题】:Update query with 2 tables使用 2 个表更新查询
【发布时间】:2020-08-05 21:53:23
【问题描述】:

我有 2 个表,table1 和 table2。

table1 有 2 列:status 和 id

table2 有 2 列:id 和 name

我有一个接收名称的函数,我想将 table1.status 更新为 0,其中 table1.id = table2.id 和 table2.name = 我收到的名称。

我试着环顾四周,但我尝试过的每个查询都失败了。

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    你可以使用update:

    update table1 t1
         set status = 0
         where exists (select 1 
                       from table2 t2
                       where t2.id = t1.id and t2.name = :name
                      );
    

    【讨论】:

    • @MayaSaias 如果答案解决了您的问题,您可以接受。这样你就可以奖励回答的人。它还显示了未来遇到相同问题的人,哪个解决方案有效。
    • @Gordon,我赞成你的回答,因为它解决了问题,而且用户显然忘记了接受它。我也遭受了很多痛苦,为此,我约束自己在人们显然很好的时候,以及当他们解决问题本身以及提出问题的人忘记或不在乎时,都会对他们的答案进行投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-27
    • 2018-02-20
    • 2011-05-19
    相关资源
    最近更新 更多