The key to writing queries is to break the problem down to steps.
1) Determine the highest historyid per callid. This requires an aggregate query or in Access terminology, a Totals query.
SELECT hicallid, max(hihistoryid) AS maxhistid
FROM dbo_HISTORY
GROUP BY hicallid
2) Select the records from History that have the highest historyid. I've chosen to do this by JOINing the History table to the query created in step one. You could use other query techniques.
SELECT h.HiCallID, h.HiHistoryID, h.HiDate
FROM dbo_HISTORY AS h
INNER JOIN
[SELECT hicallid, max(hihistoryid) AS maxhistid
FROM dbo_HISTORY
GROUP BY hicallid]. AS q
ON (h.HiCallID = q.hicallid)
AND (h.HiHistoryID = q.maxhistid)
3) Create a final query that adds the Call table data to the History data selected. So far as I can determine, the following query will select the rows and columns you need.
SELECT
c.CaCallID, c.CaStartDate, c.CaCurrentState,
c.CaCustomerID, h.HiCallID, h.HiHistoryID, h.HiDate
FROM dbo_CALL AS c
INNER JOIN (dbo_HISTORY AS h
INNER JOIN
[SELECT hicallid, max(hihistoryid) AS maxhistid
FROM dbo_HISTORY
GROUP BY hicallid]. AS q
ON (h.HiCallID = q.hicallid)
AND (h.HiHistoryID = q.maxhistid))
ON c.CaCallID = h.HiCallID;
I note that the "dbo_" prefix on the tables. If these are linked SQL Server tables, you will find it more efficient to create this query in SQL Server as a View and then link the view or select from the view using a pass-through query. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.