0

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

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

谢谢!

4

1 回答 1

0

现在我知道我不能在子查询中加入我的更新表。感谢马克 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
    )
)
于 2013-04-16T16:14:21.420 回答