Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join 2 tables on key id with 1 to many, bring back the newest date value on the many side 1

Status
Not open for further replies.

08211987

Programmer
Apr 20, 2012
187
0
0
US
I have 2 tables with a 1 to many join and the key id is the join. The many table has a date and I would only like the record with the most recent date to be joined if there are more than one. I built a query where the date field criteria is max([date field]). That field could be Null but I am not checking for that, could that be the issue?
Appreciate any assistance!
 
Make a query that groups by Key ID and gets the max of the date.

Then inner join that query to limit the results.
 
Are you saying for the table that has multiple dates, make a query for it and group by ID and then do a max for date - then join the other table for it? Regardless I am having trouble with the syntax for the Max.

I tried max([date field]) within that field in the query criteria
Thanks
 
08211987 said:
I built a query where the date field criteria is max([date field]).

Show the whole query here. It will be easier to help you.


---- Andy

There is a great need for a sarcasm font.
 
I wish I could but I can't send emails to my home from work. I tried what Lameid said above to group the table that has the multiple recs by ID and then the max of the date "Max([Table2.Date]) in criteria and it only brings back 2 records, there are 1000's.

Then I tried where I have table1 where the key is on another table and I want some data from Table2 where the keys are equal but I only want the information from table2 where the date is the newest but it is still bring in all dub records with the key field.
 
Change your query to SQL view and copy and paste the SQL statement here.
 
Hi thanks, I now think it is working thanks! I'll find out at work on Monday with new data!
 
Somehow I managed to get the Max to work to give me results I was looking for I'm just not sure how to get the Join that I need.

I now have the results of 2 fields containing ID and 1 date representing the max date in a separate file called "Max Table". Some of the IDs do not have a date. I have the original file that has duplicate IDs but different dates or no dates called "Table1". How would I create a query(s) that would join "Table1" to "Max Table" and append to a new "Table2" Providing no duplicate IDs and contain the max date I saw in "Max Table" with all the other fields?

Appreciate your help! Thank you.
 
I believe I have resolved this one as well, I'll find out when I use my real data on Monday. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top