我有 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”輸出
uj5u.com熱心網友回復:
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';
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/315250.html
標籤:sql 数据库 PostgreSQL 加入
