I have the following problem. I need to make replacements in a field with values from another table. Example :
Table1
id | value
=====================================
AAAAA '10,40,100,200,300,400,500,600'
Table2
valueold | valuenew
===================
10 95
40 30
500 250
The expected result :
id | value
=====================================
AAAAA '95,30,100,200,300,400,250,600'
Mysql query is :
update table1 as t1 inner join (select valueold, valuenew from table2) as t2
on find_in_set(t2.valueold,t1.value)
set value = (select result from
(SELECT id,value,valueold,valuenew,
trim(',' from concat_ws(',',substring_index(value,',',find_in_set(valueold,value)-1)
,valuenew, substring(value,length(substring_index(value,',',find_in_set(valueold,value)) )+2) )) as result
FROM table1 as st1 inner join (select valueold, valuenew from table2) as st2
on find_in_set(st2.valueold,st1.value)) as tresult
where tresult.id = t1.id and tresult.valueold=t2.valueold and tresult.valuenew=t2.valuenew
)
This query only update de first record ... Any ideas. Thanks