MySQL UPDATE and CASE -


new mysql (coming oracle), , have update :

update the_table set the_col = 'the_value',     the_col2 = case when the_col = 'the_value' 'x' else 'y' end = 1; 

the idea set the_col2 'x' if the_col set 'the_value', otherwise set 'y'.

what seeing the_col being updated fine, the_col2.

i not getting error reported assuming syntax/usage ok.

it if "set the_col = 'the_value'" sets value when referenced in case has new value. think unlikely, seems happening.

what want test column's value pre-update.

i don't think the_col has new value when set the_col2 case...

but 1 way find out - run update twice, doing the_col, the_col2. compare answers (you'll have - should - make temporary table safe. note: create temporary test table (since you're new mysql , might different), a) run describe your_table; b) use values in create table temp_table; c) create subquery read out rows in your_table , insert them temp_table - e.g. insert temp_table values (select * table). luck.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -