MySql - Way to update portion of a string with part of another string? -


i'm looking way replace portion of string part of string same row via mysql query.

for example, if have records title='blablabla - xx.yy.zzzz' , want add string, zzzz, field - extra_fields format '[{"value":"zzzz"}]'

original table:

title | extra_field -------------------- 19.02.1996 | [empty] 13.05.1815 | [empty] 22.03.2016 | [empty] 

after update need:

title | extra_field ------------------- 19.02.1996 | year 1996  13.05.1815 | year 1815  22.03.2016 | year 2016 

the query solution

update yourtable set extra_field = concat('year ', substring(title,7)) 

or

update yourtable set extra_field = concat('year ', substring(title,-4)) 

Comments

Popular posts from this blog

sql - can we replace full join with union of left and right join? why not? -

javascript - Parallax scrolling and fixed footer code causing width issues -

iOS: Performance of reloading UIImage(name:...) -