我想根据条件从表中选择一些id
,然后更新它们。
UPDATE user_feed
SET `status` = 'DELETED'
WHERE
id IN (
SELECT
feed.id
FROM
user_activity act
JOIN user_feed feed ON act.id = feed.activity_id
WHERE
act.uid = 16
AND feed. STATUS = 'ACTIVE'
)
显示此错误
[SQL] UPDATE user_feed set
status
=' DELETED'其中id IN(选择 来自user_activity的feed.id在act.id =上加入user_feed feed feed.activity_id where act.uid = 16 and feed.status =' ACTIVE')[错误] 1093 - 您无法指定目标表' user_feed'用于更新 FROM子句
答案 0 :(得分:1)
在MySQL中,您可以在join
语句中使用update
。我想这就是你想要的:
UPDATE user_feed f join
user_activity a
on a.id = f.activity_id and a.uid = 16
set f.`status` = 'DELETED'
Where f.status = 'ACTIVE';