L
LMC
When I apply a recursive relationship to a series of MS-Access 2003 tables
and queries (see simplified examples below), it returns extra records that it
shouldn't. I would appreciate any guidance on figuring out why and how to fix
it or if there is a better way of going about it.
I have three tables... Tables A and B have a many-to-many relationship
establised in Table C.
Tbl-A_________ Tbl-B__________ Tbl-C___________
fld-A-id fld-A fld-B-id fld-B fld-A-id fld-B-id
A1 a B1 b A1 B1
A2 aa B2 bb A1 B2
A3 aaa B3 bbb A3 B2
A4 aaaa B4 bbbb A4 B4
I have two quieries built on the above tables. Query-A returns all of
Table-A records and the relational Field-B-id values from Table-C. Query-BA
returns all of Table-B records and the relational values from all fields in
Query-A.
Qry-A_____________________________
Tbl-A__________ Tbl-C___________
fld-A-id fld-A fld-A-id fld-B-id
A1 a A1 B1
A2 aa A1 B2
A3 aaa A3 B2
A4 aaaa A4 B4
Qry-BA__________________________
Tbl-B__________ Qry-A________
fld-B-id fld-B fld-A-id fld-A
B1 b A1 a
B2 bb A1 a
B2 bb A3 aaa
B3 bbb null null
B4 bbbb A4 aaaa
A form button initiates code to save Query-BA to a table and flatten
normalized Field-A values based on duplicate Field-B values. My relational
theory works fine up to this point.
Tbl-BA______________________________
fld-B-id fld-B fld-A-id fld-A (flat)
B1 b A1 a
B2 bb A1, A3 a, aaa
B3 bbb null null
B4 bbbb A4 aaaa
My problem resides with the recursive part of Query-ABA that returns all
Query-A records with related Table-BA records including the code-flattened
values.
Expected Qry-ABA Results________________________
Qry-A________ Tbl-BA_____________________
fld-A-id fld-A fld-B-id fld-B fld-A (flat)
A1 a B1 b a
A1 a B2 bb a, aaa
A2 aa null null null
A3 aaa B2 bb a, aaa
A4 aaaa B4 bbbb aaaa
The above theory works as expected when I implement it in a database using
only the sample content explained above. But in my active database,
containing more complicted values, the results below is what I get. It
returns extra derived rows where Query-A records return empty Tbl-BA values
as well as repeated identical rows. It does the same thing even if I change
the query join from a left join to an inner join.
Example of Problem Qry-ABA Results_______________
Qry-A_________ Tbl-BA_____________________
fld-A-id fld-A fld-B-id fld-B fld-A (flat)
A1 a null null null
A1 a null null null
A1 a B1 b a
A1 a B2 bb a, aaa
A1 a B1 b a
A1 a B2 bb a, aaa
A2 aa null null null
A3 aaa null null null
A3 aaa B2 bb a, aaa
A4 aaaa B4 bbbb aaaa
I apologize for the lengthy explaination; I didn't see that it could be
explained more succinctly. Again, I appreciate any sort of advice.
and queries (see simplified examples below), it returns extra records that it
shouldn't. I would appreciate any guidance on figuring out why and how to fix
it or if there is a better way of going about it.
I have three tables... Tables A and B have a many-to-many relationship
establised in Table C.
Tbl-A_________ Tbl-B__________ Tbl-C___________
fld-A-id fld-A fld-B-id fld-B fld-A-id fld-B-id
A1 a B1 b A1 B1
A2 aa B2 bb A1 B2
A3 aaa B3 bbb A3 B2
A4 aaaa B4 bbbb A4 B4
I have two quieries built on the above tables. Query-A returns all of
Table-A records and the relational Field-B-id values from Table-C. Query-BA
returns all of Table-B records and the relational values from all fields in
Query-A.
Qry-A_____________________________
Tbl-A__________ Tbl-C___________
fld-A-id fld-A fld-A-id fld-B-id
A1 a A1 B1
A2 aa A1 B2
A3 aaa A3 B2
A4 aaaa A4 B4
Qry-BA__________________________
Tbl-B__________ Qry-A________
fld-B-id fld-B fld-A-id fld-A
B1 b A1 a
B2 bb A1 a
B2 bb A3 aaa
B3 bbb null null
B4 bbbb A4 aaaa
A form button initiates code to save Query-BA to a table and flatten
normalized Field-A values based on duplicate Field-B values. My relational
theory works fine up to this point.
Tbl-BA______________________________
fld-B-id fld-B fld-A-id fld-A (flat)
B1 b A1 a
B2 bb A1, A3 a, aaa
B3 bbb null null
B4 bbbb A4 aaaa
My problem resides with the recursive part of Query-ABA that returns all
Query-A records with related Table-BA records including the code-flattened
values.
Expected Qry-ABA Results________________________
Qry-A________ Tbl-BA_____________________
fld-A-id fld-A fld-B-id fld-B fld-A (flat)
A1 a B1 b a
A1 a B2 bb a, aaa
A2 aa null null null
A3 aaa B2 bb a, aaa
A4 aaaa B4 bbbb aaaa
The above theory works as expected when I implement it in a database using
only the sample content explained above. But in my active database,
containing more complicted values, the results below is what I get. It
returns extra derived rows where Query-A records return empty Tbl-BA values
as well as repeated identical rows. It does the same thing even if I change
the query join from a left join to an inner join.
Example of Problem Qry-ABA Results_______________
Qry-A_________ Tbl-BA_____________________
fld-A-id fld-A fld-B-id fld-B fld-A (flat)
A1 a null null null
A1 a null null null
A1 a B1 b a
A1 a B2 bb a, aaa
A1 a B1 b a
A1 a B2 bb a, aaa
A2 aa null null null
A3 aaa null null null
A3 aaa B2 bb a, aaa
A4 aaaa B4 bbbb aaaa
I apologize for the lengthy explaination; I didn't see that it could be
explained more succinctly. Again, I appreciate any sort of advice.