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

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -