gpt4 book ai didi

mysql - 目标表不可更新

转载 作者:行者123 更新时间:2023-11-29 05:25:36 25 4
gpt4 key购买 nike

我有以下查询

 UPDATE (SELECT user_id,method_id FROM User AS U
JOIN Address AS A
ON A.user_id=U.id
JOIN Shipping AS S
ON S.address_id= A.id WHERE user_id=1) AS T
SET T.method_id=5;

我收到错误消息“更新的目标表 T 不可更新”。如何更改我的查询以更新子查询中的列?任何解释都会很棒我正在使用 MySQL

最佳答案

UPDATE Shipping s
JOIN Address AS a ON s.address_id = a.id
SET s.method_id = 5
WHERE a.user_id = 1

不需要加入User 表,因为user_idAddress 表中。如果确实需要在更新前检查用户是否存在,可以是:

UPDATE Shipping s
JOIN Address AS a ON s.address_id = a.id
JOIN User AS u ON a.user_id = u.id
SET s.method_id = 5
WHERE u.id = 1

关于mysql - 目标表不可更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20749540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com