我有 2 个表(“users”和“user_workplace”)。表“用户”有列 id、first_name、last_name。表“user_workplace”有 id、user_id(user_workplace.user_id = users.id)、status(DISABLED 或 ACTIVE)。
我有用户的名字和姓氏,我需要将表“user_workplace”中的状态更新为“禁用”。
我怎么能做到这一点?
我已经尝试过这样的事情,但是出现了错误(错误:缺少表“用户”第 2 行的 FROM 子句条目:WHERE user_workplace.user_id = users.id 和):
UPDATE user_workplace SET status = 'DISABLED'
WHERE user_workplace.user_id = users.id and
users.first_name like 'John ' and
users.last_name like 'Doe';
和这个:
UPDATE
public.user_workplace
SET
status = 'DISABLED'
FROM
public.users AS Table_u,
public.user_workplace AS Table_uw
WHERE
Table_uw.user_id = Table_u.id and
Table_u.first_name like 'John ' and
Table_u.last_name like 'Doe';
有“UPDATE 0”输出
UPDATE user_workplace
SET status = 'DISABLED'
from users
WHERE user_workplace.user_id = users.id and
users.first_name like 'John ' and
users.last_name like 'Doe';
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句