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

c# SetCompatibleTextRenderingDefault must be called before the first -

c++ - Fill runtime data at compile time with templates -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -