我可能做错了什么,我之前搜索过它,我发现一些解决方法告诉我它在 MySQL 上不可能,其他人发布它是由于 MySQL 优化器,所以你可以简单地关闭它并继续,但是这对我不起作用。
我只想要一个简单的解决方法来解决这个问题。我可以找到 id_address_delivery 和 id_address_invoice 的唯一表来自 orders 表,此数据也在其他表上,但可以为空,因此无法在其他地方搜索它。
SET optimizer_switch = 'derived_merge=off';
update orders
set id_customer = (select id_customer from customer where email like 'foo@foo.com'),
id_address_delivery = (select id_address_delivery from orders where id_customer = (select id_customer from customer where email like 'foo@foo.com') LIMIT 1),
id_address_invoice = (select id_address_invoice from orders where id_customer = (select id_customer from customer where email like 'foo@foo.com') LIMIT 1)
where id_customer = (select id_customer from customer where email like 'foo2@foo2.com');
我收到错误代码:1093。即使我申请,您也无法在 mysql 工作台上的 FROM 子句中指定目标表“订单”进行更新
SET optimizer_switch = 'derived_merge=off';
有没有办法处理这种情况?我感谢设置一些变量,例如:
SET @iad = (select id_address_delivery from orders where id_customer = (select id_customer from customer where email like 'foo@foo.com') LIMIT 1);
然后将此 var 设置为如下值:
id_address_delivery = @iad;
执行此操作时我没有收到错误响应,但它持续了很长时间(我完全不知道为什么)并且出现 tiemout 消息(30 秒)我尝试将其设置为 120 秒并获得相同的超时消息。
编辑:
我尝试使用别名但没有结果。同样的错误:
update orders AS sor
set sor.id_customer = (select id_customer from customer where email like 'foo@foo.com'),
sor.id_address_delivery = (select a.id_address_delivery from orders as a where a.id_customer = (select id_customer from customer where email like 'foo@foo.com') LIMIT 1),
sor.id_address_invoice = (select b.id_address_invoice from orders as b where b.id_customer = (select id_customer from customer where email like 'foo@foo.com') LIMIT 1)
where pso.id_customer = (select id_customer from customer where email like 'foo2@foo2.com');
/编辑:
我阅读了一些被标记为相同问题的帖子,但在那里我找到了其他条款的一些解决方法,我无法弄清楚如何在我的特定情况下应用相同的方法。
我该如何进行?谢谢。