I have a query from my previous question (link) about a complex select,
and my question is, how can I write an update query for result of this query, to change fet_id to some new value.
Note that this query will select rows from a queue until rcpts_count reaches 1000, (for traffic controlling). more information about this query is, in this question
SELECT NULL AS msg_id, NULL AS total, NULL AS found
FROM dual
WHERE (
@total :=0
OR
@found :=0
)
UNION
SELECT msg_id, @total AS total, @found :=1 AS found
FROM messages_queue
WHERE (
@total := @total + rcpts_count
)
AND @total <1000
UNION
SELECT msg_id, rcpts_count AS total, 0 AS found
FROM messages_queue
WHERE IF( @found =0, @found :=1, 0 )
If you’re trying to update all the records within the set, you could write a query like this:
However, depending on your activity, this isn’t a safe approach, as the records returned from the query could change between the two requests.
I would recommend one of the following approaches: