I have this query, I want to be able to update the exec value to TRUE when my program finishes to execute a request and save it to my database to use it as a queue for when I have multiple executions, however, whenever I try with this query it gives me an error.
UPDATE motor
SET exec=1
where time=(SELECT max(time)
FROM motor
WHERE exec=0);
Error:
ERROR 1093 (HY000): You can't specify target table 'motor' for update in FROM clause
How can I do this?
This is because your UPDATE could be cycling.
Use this code instead of :
UPDATE motor
SET exec = 1
WHERE exec = 0
ORDER BY time DESC
LIMIT 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With