So I'm a bit rusty in SQL and could really need some help here - pretty please.
I have an online shop system based on MS Access in my hands and I need to export all possible product variants.
I have a table "VariantTypes" which contains all needed information. It looks like this:
ProductFKID | VariantTypeFKID | VariantValueFKID | Surcharge
The data for one product looks like this:
2 | 3 | 12 | 0,00 €
2 | 3 | 13 | 39,00 €
2 | 3 | 14 | 39,00 €
2 | 134 | 556 | 0,00 €
2 | 134 | 557 | 90,00 €
2 | 134 | 558 | 90,00 €
Now for the new import I need every possible variant combination, which should look like this:
2 | 3 | 12 | 0,00 € | 134 | 556 | 0,00 €
2 | 3 | 12 | 0,00 € | 134 | 557 | 90,00 €
2 | 3 | 12 | 0,00 € | 134 | 558 | 90,00 €
2 | 3 | 13 | 39,00 € | 134 | 556 | 0,00 €
2 | 3 | 13 | 39,00 € | 134 | 557 | 90,00 €
2 | 3 | 13 | 39,00 € | 134 | 558 | 90,00 €
2 | 3 | 14 | 39,00 € | 134 | 556 | 0,00 €
2 | 3 | 14 | 39,00 € | 134 | 557 | 90,00 €
2 | 3 | 14 | 39,00 € | 134 | 558 | 90,00 €
And of course, if I have 3 variant types for one product, it should work the same way. The best example for this is:
A product with the colors BLACK, WHITE, RED and sizes S,M,L and I need:
Black - S | Black - M | Black - L| White - S | White - M | White - L | Red - S |...
I'm sure there is an easy way to solve this, 'cause I learned it quite some time ago in school. I just can't remember how.
Thanks for your help in advance!
Greets, KaptainEaglu
UPDATE:
I managed to create following statement to create the cartesian product:
SELECT v1.ProductID, v1.Name, v1.Value, v1.Surcharge, v2.Name, v2.Value, v2.Surcharge
FROM [smartstore].[dbo].[smarstorevariants] v1
CROSS JOIN [smartstore].[dbo].[smarstorevariants] v2
WHERE v1.ProductID = v2.ProductID AND v1.Name != v2.Name
ORDER BY v1.ProductID desc
But as a result I don't get 9 combinations as result but 18. E.g.: Black-S, Black-M,... and S-Black, S-White,...
I know, technically they are different combinations but for my shop-export they are double combinations.
Any ideas on how to solve this?