How do I get the Max Date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query that has the following fields:

PatientID
CaseNo
CaseBgnDt
CaseEndDt
RN
LogFrmDt
LogThruDt
LogType

There can be more than 1 log in the table and I only want to pull the most
recent Log. How would I do this? I'm assuming I will use the LogFrmDt but I
cannot get my query to work using the Max function.

Thanks.
 
hi,

you could use a function... Max() in particular, as in the following example:

SELECT tbl_name.PatientID, Max(tbl_name.LogFrmDt ) AS last_LogFrmDt
FROM tbl_name
GROUP BY tbl_name.PatientID;

To the preceding, you can add your WHERE clause limiting output records as
desired.

hope this helps,
geebee
 
It does not supply the OTHER fields of the row associated to the MAX, for
each patientID. If ONLY the max value is required, that is fine. As example,
if you have a library, you may want WHEN, for the last time, each book has
been out: SELECT bookID, MAX(outDate) FROM... would do, but if, in
addition, you want also know "by who", you need the associated fields to
that max.


Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top