I have this SQL query, which is wrong. I want to update the field "prevmonth" in the wins table, but only for the record that has the maximum value for the field "month_wins".
UPDATE wins
SET prevmonth_top=1
WHERE month_wins = (SELECT MAX(month_wins) FROM wins)
Error message:
#1093 – You can’t specify target table ‘wins’ for update in FROM clause
But how can I do this?
Try this trick:
Or something like this:
It is the same as You can’t specify target table ‘table_name’ for update in FROM clause.