我一直在寻找,但我仍然不明白为什么这是错的。我检查了子查询,他们只返回了一行。
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
谢谢!
答案 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
)
)