BaldyWeb
Get Information Associated with the Most Recent Entry From a Table
Let's say you have a table with vehicles, dates, and various other information. You want the information from the last entry for each vehicle. One solution involves two queries. The first gets the most recent entry for each car (this is named qryMaxDates):
SELECT Max(VehicleMiles.DorDate) AS MaxDate,
VehicleMiles.CarNum
FROM VehicleMiles
GROUP BY VehicleMiles.CarNum
Then in a second query you join the original table and qryMaxDates to get the other information associated with that last record:
SELECT VehicleMiles.*
FROM VehicleMiles INNER JOIN qryMaxDates
ON (VehicleMiles.CarNum =
qryMaxDates.CarNum)
AND (VehicleMiles.DorDate = qryMaxDates.MaxDate)