I am having a hard time to get a - seemingly simple - right in SQL. I am using MS Access but I guess it doesn't really matter here. My data structure looks like this:
So tblA has the "Products", tblB the "Components" and tblC the "Modules". It's just an example obviously.
tblA ("Product") has m:n relation to tblB ("Component"), i.e. a product consists of some components and components can belong to many products. tblB ("Component") has m:n relation to tblC ("Modules"), i.e. a component consists of modules and modules can belong to many components. Now the twist is, that I also have a m:n relation between tblA and tblC, i.e. a mapping of products and modules. This is due to the fact that the "configuration" of a component can be different depending on the product for which is it. So for "Product 1" "Component 2" needs to consist of "Module 1" and "Module 2" while for "Product 2" "Component 2" is just "Module 2".
I want a query with a result like this
|Product|Component|Module|
|-------|---------|------|
|Prod1 |C1 | |
|Prod1 |C2 | |
|Prod1 |C2 |M1 |
|Prod1 |C2 |M2 |
|Prod2 |C2 | |
|Prod2 |C2 |M2 |
|Prod2 |C3 | |
|Prod2 |C3 |M3 |
where I have "Prod1" and "Prod2" in tblA; "C1", "C2", "C3" in tblB and "M1","M2","M3" in tblC. Relations are
So essentially I want a table with Product, Component, Module that holds all the combinations Product+
Now with a SQL Query
SELECT tblA.Product,
tblB.Component,
tblC.Module
FROM tblC
INNER JOIN ((tblA
INNER JOIN (tblB
INNER JOIN mapAB ON tblB.[Component] = mapAB.[Component]) ON tblA.[Product] = mapAB.[Product])
INNER JOIN mapAC ON tblA.Product = mapAC.Product) ON tblC.Module = mapAC.Module;
I get
which is understandable but not what I want. I have tried to do first a join of tblA and tblB and to combine this with a LEFT JOIN (or RIGHT JOIN) with a join of tblB and tblC but this gives "unsupported join operation" errors.
Any ideas on how to approach this problem?





