J
John Seghers
I'm helping a friend with a homework assignment and we've run into something
that makes no sense to us.
We have a normalized database of several tables. We have several queries
that aggregate data in useful ways, pulling together sums and counts of
data.
There are two queries that each have an ID and a few columns of information
that we want to join into one query to be used for a report.
A simplified version of the tables and queries is:
tblNames: ID, Name
1 Name1
2 Name2
3 Name3
4 Name4
Q1: Aggregate some data from other tables
Q2: further aggregate the results from Q1. This produces a result set of:
ID Name value1 value2
3 Name3 8 7
2 Name2 7 4
4 Name4 7 4
1 Name1 5 1
Q3: Performs another aggregation resulting in the result set:
ID Name valueX valueY Total
3 Name3 2 1 3
2 Name2 0 3 3
4 Name4 2 1 3
1 Name1 2 1 3
As you can see, the result sets each have all four of the IDs present.
The final Query joins Q2 with Q3:
SELECT Q3.Name, Q3.Total, Q2.value1, Q2.value2
FROM Q3, Q2
WHERE Q3.ID=Q2.ID;
This returns an empty result set.
Eliminating the WHERE (and adding columns for the IDs from each of
Q2 and Q3clause returns the expected 16 row result set,
of which four rows clearly have identical IDs.
Indeed, using Q2 and Q3 as Make Table queries, and then performing the
same join query on the tables works as expected. Yet trying to perform
the join between Q3 and T2 (the table produced from Q2) results in the
empty set. I didn't try Q2 with T3...
Any ideas as to what might be happening?
- John
that makes no sense to us.
We have a normalized database of several tables. We have several queries
that aggregate data in useful ways, pulling together sums and counts of
data.
There are two queries that each have an ID and a few columns of information
that we want to join into one query to be used for a report.
A simplified version of the tables and queries is:
tblNames: ID, Name
1 Name1
2 Name2
3 Name3
4 Name4
Q1: Aggregate some data from other tables
Q2: further aggregate the results from Q1. This produces a result set of:
ID Name value1 value2
3 Name3 8 7
2 Name2 7 4
4 Name4 7 4
1 Name1 5 1
Q3: Performs another aggregation resulting in the result set:
ID Name valueX valueY Total
3 Name3 2 1 3
2 Name2 0 3 3
4 Name4 2 1 3
1 Name1 2 1 3
As you can see, the result sets each have all four of the IDs present.
The final Query joins Q2 with Q3:
SELECT Q3.Name, Q3.Total, Q2.value1, Q2.value2
FROM Q3, Q2
WHERE Q3.ID=Q2.ID;
This returns an empty result set.
Eliminating the WHERE (and adding columns for the IDs from each of
Q2 and Q3clause returns the expected 16 row result set,
of which four rows clearly have identical IDs.
Indeed, using Q2 and Q3 as Make Table queries, and then performing the
same join query on the tables works as expected. Yet trying to perform
the join between Q3 and T2 (the table produced from Q2) results in the
empty set. I didn't try Q2 with T3...
Any ideas as to what might be happening?
- John