mysql - do X in column A if Y found in column B -


i have done research on matter , found works , easy:

update `table` set `a`=a+200 b='y'; 

this works if column b has single y value.

but here comes 'hard' part. column b has multiple values this: ,y1,y2,y3,y4,

i a+200 executed if y3 found in column b regardless of other values are. not familiar arrays or whatever required search through column b y3 value. appreciated. thank you!

you can either use find_in_set or match against regular expression regexp

example:

update `table` set `a` = `a` + 200 find_in_set('y3', `b`) 

or

update `table` set `a` = `a` + 200 `b` regexp '(^|,)y3(,|$)' 

aaand glglgl said. normalize database: wikipedia: database normalization


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -