我可能做错了什么,我以前搜索过它,我发现一些解决方法,告诉我这在mysql上是不可能的,其他人发布说,这是由于mysql优化器,所以你可以简单地关闭它并继续,但它不工作,我。
我只想要一个简单的解决方法来处理这个问题。我唯一能找到id\u address\u delivery和id\u address\u 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工作台上为updatein from子句指定目标表'orders',即使我是appply
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秒,并得到相同的超时消息。
编辑:
我试过用alias,但没有结果。相同错误:
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');
/编辑:
我读了一些贴有相同问题标签的帖子,但是在那里我找到了一些其他条款的解决方法,我不知道如何将它们应用到我的特定案例中。
我该怎么办?谢谢。
3条答案
按热度按时间gopyfrb31#
另一个答案是,如果要对表执行更新/插入/删除操作,则不能在内部查询中引用该表(但是可以引用外部表中的字段…)
检查以下与您的问题相同的问题并解决它们。
mysql错误1093-无法在from子句中指定更新的目标表
不能在from子句中指定更新的目标表
x4shl7ld2#
0h4hbjxa3#
我终于处理了它设置变量,仍然不知道为什么这导致了超时之前。我在where子句上添加了null保护,以便在某些var init失败时不插入null值。
有一份我的工作示例供您参考:
它只是将子查询值抽象为一个变量,并将其放置在子查询所处的位置。我以前做过,不需要这种变通方法,但我认为它是在SQLServer上(也许)。
希望它能帮助别人。