Need Current state for each record

L

littleccguy

Just learning. Please be gentle.

I have two tables - ReportRequest (Main Table) and ReportHistory
(progress tracking). ReportRequest shows each record once (RequestID
is primary key). The ReportHistory tracks everytime the request has
changed status (HistoryID is primary key and RequestID is in table for
join purposes).

I need to edit my query so that every RequestID shows once with the
most current (highest) HistoryID.

Told you I was just learning.

Win XP and Access 2003

Here is the starting Query

SELECT ReportRequest.RequestId, ReportHistory.HistoryID,
ReportHistory.RequestID, ReportHistory.ReportStatus,
ReportHistory.ReportStatusChangeDate, ReportHistory.Notes
FROM ReportRequest INNER JOIN ReportHistory ON ReportRequest.RequestId
= ReportHistory.RequestID;

Thanks
 
G

Guest

Try this. I only tested it with a small record set.
SELECT ReportRequest.RequestId, Max(ReportHistory.ReportStatusChangeDate) AS
MaxOfReportStatusChangeDate, Last(ReportHistory.ReportStatus) AS
LastOfReportStatus, ReportHistory.Notes
FROM ReportRequest INNER JOIN ReportHistory ON ReportRequest.RequestId =
ReportHistory.RequestId
GROUP BY ReportRequest.RequestId, ReportHistory.Notes;
 
L

littleccguy

Unfortunately that didn't work. It returned all rows.

Although, I kind of see where you are going with that.
 
R

Roger Carlson

I'd try a subquery, something like this:

SELECT ReportRequest.RequestId, ReportHistory.HistoryID,
ReportHistory.RequestID, ReportHistory.ReportStatus,
ReportHistory.ReportStatusChangeDate, ReportHistory.Notes
FROM ReportRequest INNER JOIN ReportHistory ON ReportRequest.RequestId =
ReportHistory.RequestID
WHERE ReportHistory.HistoryID In (SELECT Max(HistoryID) as MaxID FROM
ReportHistory GROUP BY RequestID);

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 

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

Top