a alias is not known inside 2nd query.
Why do you open a 2nd thread? What about the first one?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have an average table and I want to update with subquery, but return this error thanks for help
query :
UPDATE averages a,
(SELECT SUM(qty*cost) AS total_cost
FROM averages
WHERE averages.parent_id = a.product_id
AND averages.invoice_id = a.invoice_id) as parent
SET cost = parent.total_cost
error :
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a.product_id' in 'where clause' (SQL: UPDATE averages a, (SELECT SUM(qty) AS total_cost FROM averages WHERE averages.parent_id = a.product_id AND averages.invoice_id = a.invoice_id) as parent SET cost = parent.total_cost)
Please or to participate in this conversation.