What I have is two tables. The first has a primary key ID, while the second has a compound key ID and Nbr. There is a one to many relationship between the two tables.
I create a query using QBE. I inserted the first table, the added the second table twice. I connected each table via the ID field using left joins.
I then used a constraint where in the first copy of table 2, the Nbr should equal 1. In the second copy of table 2 the constraint is Nbr = 2.
My result is not what I expected. I expected The ID to show for all records, and if there was a matching record and Nbr equaled 1 or 2 these values should show up.
What I got was only those records where the ID had two records, with nbr = 1 and nbr = 2.
So I did get
Code:
ID table2.Nbr table2_1.Nbr
3 1 2
5 1 2
I expected (and wanted)
Code:
ID table2.Nbr table2_1.Nbr
1 1
2 1
3 1 2
4 2
5 1 2
Here is the query
Code:
SELECT Table1.ID, Table2.Nbr, Table2_1.NbrFROM (Table1 LEFT JOIN Table2 ON Table1.ID = Table2.ID) LEFT JOIN Table2 AS Table2_1 ON Table1.ID = Table2_1.ID
WHERE (((Table2.Nbr)=1) AND ((Table2_1.Nbr)=2));
Can anyone indicate how to accomplish this and where I went wrong?