Query: Getting Max Date for each person

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I am trying to obtain the most recent record for each StudentID. tnDateEntered is a date/time that contains a timestamp. I can not determine how to modify the query below.

Guidance is appreciated.

Code:
SELECT 
  tblStudentTestNeeds.tnRecordID, 
  tblStudentTestNeeds.tnStudentID, 
  tblTestInfo.tiOfficeDescription, 
  tblStudentTestNeeds.tnTestCode, 
  tblStudentTestNeeds.tnDateEntered
FROM 
  tblTestInfo INNER JOIN tblStudentTestNeeds 
  ON tblTestInfo.tiTestID = tblStudentTestNeeds.tnTestCode
ORDER BY tblStudentTestNeeds.tnDateEntered DESC;
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Take a look at creating Aggregate (Totals) Queries in Access's built-in help files. You can get things like Counts, Sums, Maximums, Minimums, etc of a "grouped" bunch of records.
 
Upvote 0
Take a look at creating Aggregate (Totals) Queries in Access's built-in help files. You can get things like Counts, Sums, Maximums, Minimums, etc of a "grouped" bunch of records.

I had tried but it was not producing the value I was looking for.

Instead of producing just one record per person, it gives me alot more.

I should receive for each tnStudent the most recent tnDateEntered and the TnTestCode and tiOfficeDescription for it.

Code:
SELECT tblStudentTestNeeds.tnStudentID, Max(tblStudentTestNeeds.tnDateEntered) AS MaxOftnDateEntered, tblStudentTestNeeds.tnTestCode, tblTestInfo.tiOfficeDescription
FROM tblStudentTestNeeds INNER JOIN tblTestInfo ON tblStudentTestNeeds.tnTestCode = tblTestInfo.tiTestID
GROUP BY tblStudentTestNeeds.tnStudentID, tblStudentTestNeeds.tnTestCode, tblTestInfo.tiOfficeDescription;
 
Upvote 0
You'll probably need to do this in two queries (or one query with a subquery).

The first query (or subquery) will be the Aggregate Query where you just have the Person ID field (Group on that) and the Date field (take Max of that). Then link that subquery back to your original table on these two fields, returning all the fields you want.
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,443
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top