【发布时间】: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 = 我收到的名称。
我试着环顾四周,但我尝试过的每个查询都失败了。
【问题讨论】:
我有 2 个表,table1 和 table2。
table1 有 2 列:status 和 id
table2 有 2 列:id 和 name
我有一个接收名称的函数,我想将 table1.status 更新为 0,其中 table1.id = table2.id 和 table2.name = 我收到的名称。
我试着环顾四周,但我尝试过的每个查询都失败了。
【问题讨论】:
你可以使用update:
update table1 t1
set status = 0
where exists (select 1
from table2 t2
where t2.id = t1.id and t2.name = :name
);
【讨论】: