I have a table with several hundred rows. I want to take the top 20 based on the value of column num and replace num with a number.
What I tried to do (which didn’t work) was:
UPDATE table
SET num = 95
WHERE id IN (SELECT id FROM table ORDER BY id DESC LIMIT 20)
Any suggestions?
There’s no need for the subquery – you can use LIMIT in an UPDATE statement on MySQL:
It’s unclear what you want to order by – I used
idbased on your subquery, but in case it needs to be by thenumvalue: