I am building the underlying database for a shop. There are 2 tables, one for garments and one which holds standard size charts. Garments are available in one or more sizes and the size charts contain several measurements for each size garment.
Example size chart table
id size waist chest hips height
0 6 56 76 82 160
0 8 60 80 86 162
0 10 64 84 90 164
0 12 68 88 94 166
1 6 57 75 82 160
1 8 61 79 86 162
1 10 62 83 90 164
1 12 63 87 94 166
Example garments table
garment_id garment_name garment_type size_chart available_sizes
0 Boating Jacket jacket 0 8,10,12
1 Polka Dot Skirt skirt 1 10,12
What I want to do is join them so that I have
garment_id ... size_chart available_sizes size_chart.id size_chart.size size_chart.(...)
0 ... 0 8,10,12 0 8
0 ... 0 8,10,12 0 10
0 ... 0 8,10,12 0 12
1 ... 1 10,12 1 10
1 ... 1 10,12 1 12
The problem I am having is how to join so that I get every number in the set (available_size) to have a corresponding entry for measurements….
Any ideas/suggestions/advice on how I am best to do this would be really useful!
Thanks.
Example garments table
Is the root of all evil – so, speak after me:
I will never ever store more than one information in a single db field, if I want to access them seperately. Never.
On a more serious note, you would want to drop the
available_sizesfield from thegarmentstable, instead do something likeand populate it. This makes it easy to mark one size as sold out, maybe even add a
qty_in_stock INTto the table, search for all garments of same type, which are available in a specific size, etc.