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
Post a Comment