I have two tables.
Table 1 Columns:
Name
Address
Height
Color
Money
ID
ID2
Table 2 Columns:
Name
Address
Height
Color
Money
ID
ID2
Table 1 has the records:
Name | Address | Height | Color | Money | ID | ID2
David | 45kkkkk | 100tt | Black | 1000 | 1 | 1
David | 45kkkkk | 100tt | Blue | 2000 | 2 | 1
David | 45kkkkk | 100tt | Red | 3000 | 3 | 1
David | 45kkkkk | 100tt | Orange | -3000 | 4 | 1
Table 2 has the records:
Name | Address | Height | Color | Money | ID | ID2
David | 45kkkkk | 100tt | Black | 1000 | 1 | 1
David | 45kkkkk | 100tt | Blue | 2000 | 2 | 1
David | 45kkkkk | 100tt | Red | 3000 | 3 | 1
When inner joined on column ID, it returns the below three records:
David 45kkkkk 100tt Black 1000 1
David 45kkkkk 100tt Blue 2000 2
David 45kkkkk 100tt Red 3000 3
However, when joined on column ID2 it's returning:
David 45kkkkk 100tt Black 1000 1 1
David 45kkkkk 100tt Blue 2000 2 1
David 45kkkkk 100tt Red 3000 3 1
David 45kkkkk 100tt Orange -3000 4 1
David 45kkkkk 100tt Black 1000 1 1
David 45kkkkk 100tt Blue 2000 2 1
David 45kkkkk 100tt Red 3000 3 1
David 45kkkkk 100tt Orange -3000 4 1
David 45kkkkk 100tt Black 1000 1 1
David 45kkkkk 100tt Blue 2000 2 1
David 45kkkkk 100tt Red 3000 3 1
David 45kkkkk 100tt Orange -3000 4 1
I expect it to return the below instead of the above because the below are all the ID2 (1s)
David 45kkkkk 100tt Black 1000 1 1
David 45kkkkk 100tt Blue 2000 2 1
David 45kkkkk 100tt Red 3000 3 1
David 45kkkkk 100tt Orange -3000 4 1
Why is Access duplicating these records? I know it's because it's matching the first table to the second table by ID2 three times for each 1 record in table 1 (so 3x4) = 12. Is there a way to avoid this?
In the end, what I really want is the three matches below:
David 45kkkkk 100tt Black 1000 1
David 45kkkkk 100tt Blue 2000 2
David 45kkkkk 100tt Red 3000 3
and this below record too (it doesn't match anything on ID1 but matches on ID2...Is there a way to pull in matches for ID2 without duplicating ID1 matches?)
David | 45kkkkk | 100tt | Orange | -3000 | 4 | 1
I did a SELECT DISTINCT SQL query to get the above four results. However, when I group them by the Money column and Sum them, it sums even the non-distinct records too. Is there a way to sum only the distinct records?