mysql - Joining multiple tables without common key -
hi have 3 tables listed below. there no common keys between tables
table 1->linkage_table
id item material color 1 keypouch * yellow 2 wallet plastic * 3 card-holder leather gold
table 2->material_table
id name 1 plastic 2 wool 3 leather
table 3->color_table
id color 1 yellow 2 green 3 orange
i wish following result set
item material color keypouch plastic yellow keypouch wool yellow keypouch leather yellow wallet plastic yellow wallet plastic green wallet plastic orange card-holder leather gold
i write sql statement join tables together.
having * in linkage table mean retrieve values either material or color table.
i in need of solution now. been trying solve more 5hours. in advance help.
one possible approach:
select l.item, m.name, c.color linkage_table l inner join material_table m on l.material = '*' or l.material = m.name inner join color_table c on l.color = '*' or l.color = c.color
explanation: query has built 'material' , 'color' tables joined either (cross-join), when '*'
given in corresponding field, or equality of these fields. , that's got using 'on l.somefield = '*' or l.somefield = joined.somefield'
clause.
Comments
Post a Comment