I’m trying to UPDATE a table based on a sub-query on itself. So I need sub-query’s result as parameters in UPDATE statement.
I tried below with no success:
UPDATE xx
INNER JOIN (
SELECT r.id as id, w.state as state
...
) yy
SET xx.state = yy.state WHERE xx.id = yy.id;
EDIT:
Full query:
UPDATE dpcio_request xx
INNER JOIN (
SELECT r.id as id, w.state as state
FROM dpcio_request r
JOIN dpcio_request_wf w
ON (w.dpcio_request_id = r.id)
WHERE w.id IN ( SELECT MAX(id)
FROM `dpcio_request_wf`
GROUP BY dpcio_request_id )
) r2 ON r1.id = r2.id
) yy ON yy.id = xx.id
SET xx.state = yy.state;
if you have no special calculation on the subquery and assuming that it is from a different table, you can directly join the tables,
UPDATE 1
here’s a simplified version of the query,