SQLite Forum

Question about UPDATE with LIMIT
Login

Question about UPDATE with LIMIT

(1.2) Originally by anonymous with edits by Richard Hipp (drh) on 2021-09-22 00:24:20 from 1.1 [link] [source]

we have the following sqlite command that works:

UPDATE feeder SET quantity = quantity + 1 WHERE quantity < 200 AND available = 1 RETURNING id, food_weigth, quantity

but we would like to add a limit 1 since we don't want to update all the feeders

something like (it doesn't work):

UPDATE feeder SET quantity = quantity + 1 WHERE quantity < 200 AND available = 1 LIMIT 1 RETURNING id, food_weigth, quantity

nyl

(2) By Larry Brasfield (larrybr) on 2021-09-22 00:39:18 in reply to 1.2 [source]

Something like: UPDATE feeder SET quantity = quantity + 1 WHERE id in ( SELECT id from feeder WHERE quantity < 200 AND available = 1 LIMIT 1 ) RETURNING id, food_weigth, quantity

(3) By anonymous on 2021-09-22 00:51:02 in reply to 2 [link] [source]

thanks a lot! nyl