Skip to content
Advertisement

MySQL: Updating all rows setting a field to 0, but setting one row’s field to 1

Is there an efficient way to update a selection of rows’ field to 0, but set One of these rows to 1 based on an ID.

Basically, I have multiple objects in a database, and I want to toggle between which one is “inuse”, so the query will set one of the rows (by id) to inuse=1 and the others to inuse=0.

Thanks 🙂

Advertisement

Answer

UPDATE `table`
SET `inuse` = (`id` = 23)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement