错误1093.您无法在FROM子句中为更新指定目标表'ps_order_history'

时间:2013-04-16 16:01:01

标签: mysql mysql-error-1093

我一直在寻找,但我仍然不明白为什么这是错的。我检查了子查询,他们只返回了一行。

UPDATE ps_order_history

SET id_order_state = 18

WHERE id_order = 
(
    SELECT max(p.id_order)
    FROM ps_orders p
    INNER JOIN ps_order_detail d ON d.id_order = p.id_order
    INNER JOIN ps_order_history oh ON oh.id_order = p.id_order
    WHERE d.product_name = "Academia Mastermaq" 

    AND p.id_customer = 
    (
        SELECT id_customer
        FROM ps_customer
        WHERE firstname = "Cristiano"
        AND lastname = "Ferreira dos Santos"
        LIMIT 1
    )
)

Error Code: 1093. You can't specify target table 'ps_order_history' 
for update in FROM clause

谢谢!

1 个答案:

答案 0 :(得分:0)

现在我知道我无法在子查询中加入我的更新表。感谢Marc B

UPDATE ps_order_history h
INNER JOIN ps_order_detail d ON d.id_order = h.id_order

SET h.id_order_state = 15

WHERE d.product_name = "Academia Mastermaq" 
AND h.id_order = 
(
    SELECT max(p.id_order)
    FROM ps_orders p
    /*INNER JOIN ps_order_detail d ON d.id_order = p.id_order
    INNER JOIN ps_order_history oh ON oh.id_order = p.id_order*/


    WHERE p.id_customer = 
    (
        SELECT id_customer
        FROM ps_customer
        WHERE firstname = "Cristiano"
        AND lastname = "Ferreira dos Santos"
        LIMIT 1
    )
)