Reputation: 456
I developed a database with Access with the next architecture:
First table:
And the second table, linked to the first one by their identifiers, that it's being used like a history, keeping some events with his responsible:
So, I'm trying to make a SQL query that brings me the last event in the history table for a determined identifier by this way:
SELECT M.ID, M.SN, Last(H.Date) AS MaxDate, Last(H.Responsible) AS LastResponsible,
Last(H.Description) AS LastDescription
FROM TABLE1 AS M INNER JOIN History AS H ON M.ID=H.ID
WHERE M.Disponible=No
GROUP BY M.ID, M.SN;
But it's bringing to me sometimes values in history that are not the last ones, why could be the reason?
Upvotes: 0
Views: 103
Reputation: 27634
You need to first group History
to find the Max entries. Make a subquery of this, and then JOIN the subquery with TABLE1
.
See this question for a good example:
Is it better / more efficient to use sub queries or SELECT statements within the WHERE clause (in MS Access)
(you want the "combined as a single query" variant).
If you can't get it to work, add a comment.
Upvotes: 1