SalisburyLad
Registered User.
- Local time
- Today, 15:41
- Joined
- Jun 12, 2010
- Messages
- 17
I would like to find out how to query records from 2 releted tables where the second table has a list of records that are date stamped but I only want to return the latest record with its corresponding data from the first table. In the attached DB I use 2 queries to acheive this but I need a SQL query that will run outside Access i.e. a SELECT query with a WHERE clause to replace:
and qryBorrowedLast:
I hope this makes sense.
TIA
Code:
SELECT tblBook.BookID, tblBook.BookName, tblBorrowedBy.BorrowedBy, tblBorrowedBy.BorrowedDate
FROM (tblBook INNER JOIN qryBorrowedLast ON tblBook.BookID = qryBorrowedLast.BookID) INNER JOIN tblBorrowedBy ON (qryBorrowedLast.MaxOfBorrowedDate = tblBorrowedBy.BorrowedDate) AND (tblBook.BookID = tblBorrowedBy.BookID);
Code:
SELECT tblBorrowedBy.BookID, Max(tblBorrowedBy.BorrowedDate) AS MaxOfBorrowedDate
FROM tblBorrowedBy
GROUP BY tblBorrowedBy.BookID;
TIA