如果table_subscription中存在帐户ID,我想设置table_account.account_do_not_email = 1,否则不管它。我们正在摆脱订阅表,只使用这种方法。
我目前使用的代码用于更新它找到的第一列但不是全部...
UPDATE table_account a
SET account_do_not_email = 1
WHERE EXISTS (SELECT 1 FROM table_subscription b WHERE b.account_id = a.account_id)
答案 0 :(得分:0)
如果两个表中都有特定的account_id,那么table_account表将会更新
UPDATE table_account a
INNER JOIN table_subscription ts
ON ts.account_id = a.account_id
SET account_do_not_email = 1
答案 1 :(得分:0)
您可以使用join
执行此操作
update table_account a
join table_subscription b on b.account_id = a.account_id
set a.account_do_not_email = 1
答案 2 :(得分:0)
你也可以这样做:
update table_account
set account_do_not_email = 1
where account_id in (select account_id from table_subscription)