I may be doing something wrong, I searched for it before and I find some workarounds that tell me that it can't be possible on MySQL, others are posting that it's due to MySQL optimizer so you can simply turn it off and continue, but it's not working to me.
I only want a simple workaround to deal with this. The only table where I can find id_address_delivery and id_address_invoice is from the orders table, this data is on other tables too but can be null so there's no option to search for it on another place.
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');
i'm getting Error Code: 1093. You can't specify target table 'orders' for update in FROM clause on mysql workbench, even if I appply
SET optimizer_switch = 'derived_merge=off';
Are there any option to deal with this situation? i thank on setting some vars, for example:
SET @iad = (select id_address_delivery from orders where id_customer = (select id_customer from customer where email like 'foo@foo.com') LIMIT 1);
then setting this var as value like:
id_address_delivery = @iad;
I'm not getting an error response when doing it but it lasts really a lot (i exactly don't know why) and the tiemout message appear (30 seconds) I tried putting it at 120 seconds and getting the same timeout message.
EDIT:
I tried with alias but with no result. Same error:
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');
/EDIT:
I readed some posts that are tagged as the same issue but there I find some workarounds for other clauses and I can't figure out how to apply the same with my particular case.
How may I proceed? Thanks.