I have a column with accessories of products as below example:
TABLE1
ProductID accessories
1 2,3
2 1,4,5
3
4 1
5 2
It means that for the PRODUCT 2, it has the accessories product ids 1,4 and 5
and i have THE FINAL table 2 below which look like this
TABLE2
GRP ProductID accessories
a 2
b 3
c 1
d 4
e 5
so actually if using UPDATE it would be like this
TABLE2
UPDATE table t2
INNER JOIN table1 t1
On t2.ProductID = t1.ProductID
set t2.accessories = t1.accessories
GRP ProductID accessories
a 2 1,4,5
b 3
c 1 2,3
d 4 1
e 5 2
but i want to change the productIDs in the t2.accessories with the GRP character instead according to the t2.ProductID so that the FINAL table looks like this .
TABLE2
GRP ProductID accessories
a 2 c,d,e
b 3
c 1 a,b
d 4 c
e 5 a
iam really confused how to do that correctly i was able to handle this using php code, but it takes loong time becouse i have 100k products therefore i prefer to use some group_concat or concat_ws to handle this
and some t2.accessories may already be stored, therefore it should be distinct values, so there is no duplicate t2.accessories on table2
Here is the tables http://sqlfiddle.com/#!9/bfddf