Avatar of ferguson_jerald
ferguson_jerald
 asked on

MS Access query to return the most recent record from a table?

Hello Experts.

Well, apparently I lack the ability to learn from the hundreds of posts that cover this same question so I am reaching out for some guidance.

I have two tables:  tbl_emp and tbl_emp_assnmt.  tbl_emp contains all of our employees and tbl_emp_assnmt holds all their assignments.  Each employee can have multiple assignments.  I would like to pull just the most recent tbl_emp_assnmt for each employee.  Here's the query that pulls everything:

SELECT 
tbl_emp.emp_id_pk, 
tbl_emp_assnmt.entry_dt, 
tbl_emp_assnmt.unit_ddl, 
tbl_emp_assnmt.dept_ddl
FROM tbl_emp

LEFT JOIN tbl_emp_assnmt

ON  tbl_emp.emp_id_pk = tbl_emp_assnmt.emp_id_fk

Open in new window


I would like the most recent assignment based on the Assignment Entry Date (tbl_emp_assnmt.entry_dt) field.  Once catch though, not everybody has assignments yet, and I need them to be in the results of this query also.  So this query should return the most recent assignment for each employee, and just the employee (tbl_emp.emp_id_pk) if there aren't any assignments yet.

I hope this makes sense.  Any help would be greatly appreciated.  

I'm using MS Access 2010.

Thanks,
J
Microsoft AccessMicrosoft SQL Server

Avatar of undefined
Last Comment
ferguson_jerald

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Simon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ferguson_jerald

ASKER
Thanks Simon!  Everybody gets one assignment per day, never anymore so this works great for what I need.  I somebody were to get more than one I would need to see that as well.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23