更新子查询中的问题

时间:2016-05-14 09:25:29

标签: mysql database join

我有下一个查询

UPDATE (SELECT *
FROM bbdd_gestion.csvmagento as datos
INNER JOIN (SELECT va144.id as objetivo_id, va134.value as ean_final, va144.entity_id, va144.attribute_id, va144.value as objetivo_valor
    FROM bbdd_magento.catalog_product_entity_varchar AS va134 INNER JOIN bbdd_magento.catalog_product_entity_varchar AS va144
    ON va134.entity_id = va144.entity_id
    WHERE va134.attribute_id = 134 AND va144.attribute_id = 144
    AND va144.value = ''
) as final
WHERE datos.ean = final.ean_final) AS resultado
SET va144.value = resultado.marca
WHERE va144.value = '' AND resultado.ean_final = va134.value

但结果是

Error de SQL (1288): The target table resultado of the UPDATE is not updatable

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

解决方案是

UPDATE bbdd_magento.catalog_product_entity_varchar AS var144
INNER JOIN (SELECT *
FROM (SELECT *
FROM bbdd_gestion.csvmagento as datos
INNER JOIN (SELECT va144.id as objetivo_id, va134.value as ean_final, va144.entity_id, va144.attribute_id, va144.value as objetivo_valor
    FROM bbdd_magento.catalog_product_entity_varchar AS va134 INNER JOIN bbdd_magento.catalog_product_entity_varchar AS va144
    ON va134.entity_id = va144.entity_id
    WHERE va134.attribute_id = 134 AND va144.attribute_id = 144
    AND va144.value = ''
) as final
WHERE datos.ean = final.ean_final) AS resultado
WHERE resultado.ean_final = resultado.ean) as todo
SET var144.value = todo.marca
WHERE var144.entity_id = todo.entity_id
AND var144.attribute_id = 144
AND var144.value = ''