(I’m having a hard time even explaining this question)
I have 5 Tables, A, AZ, Z, BZ, B.
AZ represents a Many-to-Many relationship between A and Z.
BZ represents a Many-to-Many relationship between B and Z.
I would like a result set that is A B where B is linked to the full set of Z for a given A.
So, let’s say that Z is a Tag table and contains:
Tag1
Tag2
Tag3
A is an Object Table and contains:
ObjectA
ObjectB
ObjectC
B is a Widget Table and contains:
WidgetX
WidgetY
WidgetZ
AZ contains:
ObjectA Tag1
ObjectA Tag2
ObjectB Tag3
ObjectC Tag2
ObjectC Tag3
BZ contains:
WidgetX Tag1
WidgetX Tag2
WidgetY Tag2
WidgetY Tag3
WidgetZ Tag3
I want my result set to be:
ObjectA WidgetX
ObjectB WidgetY
ObjectB WidgetZ
ObjectC WidgetY
Is this doable in a query, or should I pull back some intermediate sets of data and iterate in code?
Okay, major edit to rejigger this based on your feedback. It’s a little kludgy, but here you go:
It uses nasty subqueries to get the right counts, and then limits our rowset based on your criteria.