Alright. I know that this use case already has a question devoted to it here but I have tried just about any syntax there and I am getting desperate.
This is my query:
with ids as (
select t.id ntid, ot.id otid, p.id npid, op.id opid, ot.company_id ocid, t.company_id ncid
from product_template t
inner join product_template ot on t.multicompany_old_id = ot.id
inner join product_product p on p.product_tmpl_id = t.id
inner join product_product op on op.product_tmpl_id = ot.id
)
update ol
set product_id = i.npid
from sale_order_line ol
inner join sale_order o on ol.order_id = o.id
inner join product_product p on ol.product_id = p.id
inner join ids i on p.id = i.opid and o.company_id = i.ncid;
Variations I have tried:
update [sale_order_line] ol
set [ol.]product_id = i.npid
from...
update sale_order_line ol
set ol.product_id = i.npid
inner join ....
update sale_order_line ol
set product_id = i.npid
from sale_order o on ol.order_id = o.id
inner join product_product p on ol.product_id = p.id
inner join ids i on p.id = i.opid and o.company_id = i.ncid
where ol.order_id = o.id;
Nothing works. Could someone help me? I guess a solution for the following simplified case also suffices:
update T
set T.value = J.value
from some_table T
inner join joined_table J on J.some_table_id = T.id;