First of all...I know it's bad to have comma separated values in tables and no I'm not able to change it.
I have several tables that contain the following data:
************** Table 1 **********
stock_id products_id stock_attributes
5271 279 1559,2764
************** Table 2 *********************
products_attributes_id products_id options_id options_values_id
1559 279 2 8
2764 279 3 63
************** Table 3 ************************
products_options_id products_options_name
2 Size
3 Color
************** Table 4 *****************
products_options_values_id products_options_values_name
14 Pink
63 Mint
13 Black
8 S
9 M
10 L
11 XL
What I'd like to do is create a query to take the field stock_attributes in Table 1 and expand it using the information in the Tables 2, 3 & 4 so I end up with the following:
*********** Resulting Table **********
stock_id products_id opt1 opt2 opt3 opt4
5271 279 Size S Color Mint
I can do this programmatically after the fact but I'm curious if it can be done in a single SQL query. I've found similar questions and answer on how to select a particular value from a comma delimited field but nothing to do this. Any help is appreciated.