Access - Join on Two Fields, With and Without Third Field in Output

exp vg
exp vg used Ask the Experts™
on
I have two tables with 15 fields, of which 3 are Last Name, First Name, and ID.

I join Last Name from Table A, to Last Name form Table B, and the same for First Name. I also then Group By to get single row values.

When I join just on names, I get an output row count of 1900 (ID is not in the query).

When I join on the two fields, Last Name, First Name - but this time have ID in the output but not joined, I get an output row count of 2100.

What i am trying to understand is why does the count go up when ID is included in Design View, but is not being joined between Tables A and B.

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I should add that the row count does not always increase after a third field is in the output (but not joined) - in another instance there was a decrease.

I just want to understand why the number changes after additional fields are joined in design view, but are not directly joined.

Thank you.
Hamed NasrRetired IT Professional
Commented:
The difference, may be because you have duplicate records in Last_Name, and First_Name
Adding ID to the Group By reduces the duplicates.

If ID is unique, you get the same total number of records when included in group by.

Check your data for duplicate field values in Last_Name, and First_Name.

Author

Commented:
The reduction in count makes sense if there are duplicates, but not when the count increases. I also just tried adding more fields to design view - but not a direct joined.  Now I see the counts increase.

Thanks.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2016

Commented:
you have records with the same Last Name and First Name BUT, different ID
Hamed NasrRetired IT Professional

Commented:
If adding a new field to Group By, adds more records, then expect few duplicates including the fields but last.

Author

Commented:
If they are different, will the row count increase or decrease - again these additional fields are not joined.

My initial take is they will increase because more rows are added to account for the different values. However, why do I see a decrease at times?

Thanks.

Author

Commented:
Ok - I see what is happening. More fields are added since there is not a definite join - and more likely an increase. The most direct and accurate ways is to join on just Last and First Names to avoid this crossover with additional fields that are not the same.
Top Expert 2016
Commented:
with these records

ID   Lastname  FirstName
1     A                 B
2     A                 B

with this query

select lastname, firstname
from table
group by  lastname, firstname

will give you one (1) record
Lastname  FirstName
A                 B

if you include the ID in the query

select ID,lastname, firstname
from table
group by  ID,lastname, firstname

you will get
ID   Lastname  FirstName
1     A                 B
2     A                 B
 
as result

Author

Commented:
Thanks Rey - please confirm that the code above accounts for the join in design view only happens between first and last name.

Author

Commented:
These explanations make sense.

Thanks so much.

Author

Commented:
Thank you.
Hamed NasrRetired IT Professional

Commented:
All depends on what you plan to do.

Our comments include assumptions on your behalf which may not be accurate,

If you have tables:
t1  3 records, t2 4 records.

Then INNER JOIN may produce up to 4 records.
Without a join you get 12 records.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial