如何在postgresql中使用更新作为内部子查询?
update unit_has_jobcard
set status = 'approval'
where id = (update jobcard_has_approvals
set approve = true
where id = 27
returning id);
我需要在单个查询中更新两个表。 addBatch
可帮助多次查询一次性查看表格。但我需要知道这是否可能。
答案 0 :(得分:2)
您需要一个公用表表达式来在一个语句中更新两个表:
with approvals as (
update jobcard_has_approvals
set approve = true
where id = 27
returning id
)
update unit_has_jobcard
set status = 'approval'
where id = (select id from approvals);