MySQL update conditions in one query (UPDATE, SET & CASE)

前端 未结 2 1546
无人及你
无人及你 2020-12-15 06:25

I\'m trying to update a set of records (boolean fields) in a single query if possible.

The input is coming from paginated radio controls, so a

2条回答
  •  遥遥无期
    2020-12-15 07:01

    You can avoid field = field

    update my_table
        set field = case
            when id in (....) then true
            when id in (...) then false
            else field
        end
    

提交回复
热议问题