G
Guest
I have two tables, Offender and Address, that are related based on the field
ID. The Address table contains multiple addresses for a given ID and an
AddrerssDate field. I need my query to select information from the Offender
table and the most recent address from the Address table based upon the
current record shown in the Offender Information form. I have reviewed past
postings and found the following example, but can't quite get the coding
right to make this work.
Example that I found:
SELECT Events.EventTime, Events.Address, Events.SubAddr, Events.UserID,
Users.FirstName, Users.Surname
FROM Events INNER JOIN Users ON Events.UserID = Users.UserID
WHERE ((((SELECT Max([EventTime]) FROM Events WHERE UserID =
Users.UserID))=(SELECT Max([EventTime]) FROM Events WHERE UserID =
Users.UserID AND SubAddr = 1)))
ORDER BY Events.UserID, Events.EventTime DESC;
BTW: As this query will return only one record per UserID, I think the
second column in the ORDER BY clause is redundant.
What I have now that returns ALL addresses:
SELECT OffenderAddress.ID, OffenderAddress.*, Offenders.FName,
Offenders.MInitial, Offenders.LName
FROM Offenders LEFT JOIN OffenderAddress ON Offenders.ID = OffenderAddress.ID
WHERE (((OffenderAddress.ID)=[Forms]![Offender Information]![ID]));
Thanks for any assistance.
Randy Hartwick
ID. The Address table contains multiple addresses for a given ID and an
AddrerssDate field. I need my query to select information from the Offender
table and the most recent address from the Address table based upon the
current record shown in the Offender Information form. I have reviewed past
postings and found the following example, but can't quite get the coding
right to make this work.
Example that I found:
SELECT Events.EventTime, Events.Address, Events.SubAddr, Events.UserID,
Users.FirstName, Users.Surname
FROM Events INNER JOIN Users ON Events.UserID = Users.UserID
WHERE ((((SELECT Max([EventTime]) FROM Events WHERE UserID =
Users.UserID))=(SELECT Max([EventTime]) FROM Events WHERE UserID =
Users.UserID AND SubAddr = 1)))
ORDER BY Events.UserID, Events.EventTime DESC;
BTW: As this query will return only one record per UserID, I think the
second column in the ORDER BY clause is redundant.
What I have now that returns ALL addresses:
SELECT OffenderAddress.ID, OffenderAddress.*, Offenders.FName,
Offenders.MInitial, Offenders.LName
FROM Offenders LEFT JOIN OffenderAddress ON Offenders.ID = OffenderAddress.ID
WHERE (((OffenderAddress.ID)=[Forms]![Offender Information]![ID]));
Thanks for any assistance.
Randy Hartwick