Update multiple rows with different values in a single query - MySQL -


i'm new mysql.

i'm using update multiple rows different values, in single query:

update categories     set order = case id         when 1 3         when 2 4         when 3 5     end,     title = case id         when 1 'new title 1'         when 2 'new title 2'         when 3 'new title 3'     end id in (1,2,3) 

i using "where" improve performance (without every row in table tested).

but if have senario (when don't want update title id 2 , 3):

update categories     set order = case id         when 1 3         when 2 4         when 3 5     end,     title = case id         when 1 'new title 1'     end id in (1,2,3) 

the above code change title id 2 , 3 "null"...

what right way make query, skip updating title id 2 , 3 , still keep performance "where id in" gives ?

maybe this

update categories     set order = case id         when 1 3         when 2 4         when 3 5     end,     title = case id         when 1 'new title 1'         when           when       end id in (1,2,3) 

set title equal when don't want update different value.

update categories     set order = case id         when 1 3         when 2 4         when 3 5     end,     title = case id         when 1 'new title 1'         else title     end id in (1,2,3) 

Comments

Popular posts from this blog

Python __call__ special method practical example -

arrays - jQuery - Retrieve values from HTML elements and return their sum -