mysql - Updating multiple rows with different values -


i got table in mysql database, 'users'. has fields 'id' , 'value'.

now, want update lots of rows in table single sql query, many rows should different value. currently, i'm using this:

update users     set value = case id         when 1 53         when 2 65         when 3 47         when 4 53         when 5 47     end id in (1,2,3,4,5) 

this works. feel optimization since there 3 or 4 different values i'm assigning rows. can see, right these 47, 53 , 65. there way can update rows same value simultaneously within same query? or, there way can optimize this?

rather doing case variable when value ..., try doing case when condition ... - so:

update users     set value = case          when id in (1,4) 53         when id = 2 65         when id in (3,5) 47     end id in (1,2,3,4,5) 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -