update test aa, ( select c.id, GROUP_CONCAT(c.prov_code) prov_code, GROUP_CONCAT(ifnull(p.name, c.prov_code)) prov_name from ( SELECT a.id, SUBSTRING_INDEX(SUBSTRING_INDEX(a.i_prov_codes, ',', b.help_topic_id + 1), ',',-1) prov_code FROM ( SELECT b.id, GROUP_CONCAT(REPLACE(prov_codes, '/', ',')) AS i_prov_codes FROM test b group by id) a JOIN mysql.help_topic b ON b.help_topic_id < (LENGTH(a.i_prov_codes) - LENGTH(REPLACE(a.i_prov_codes, ',', '')) + 1) ) c left join test_province p on p.province_code = c.prov_code group by c.id ) d set aa.cover_prov_display_name = d.prov_name where aa.prov_codes = d.prov_code and aa.id = d.id