I'm fairly new to Access.
I have the 'Inventory' table with ID
, ExprDate
, and LOT
fields, with ID be duplicatable and LOT is an unique index.
Something like this:
ID LOT ExprDate
1001 A1 30/12/22
1001 B1 30/12/23
1002 A2 30/12/23
1002 B2 30/12/24
1003 A3 30/12/25
I'm trying to make a query where it select the unique IDs with the nearest ExprDate and return their LOT, like this:
ID LOT ExprDate
1001 A1 30/12/22
1002 A2 30/12/23
1003 A3 30/12/25
but so far nothing. (I should mention ExprDate is a future date)
I've tried
SELECT *
FROM Inventory
WHERE (((Inventory.Exp)=(SELECT MIN(Inventory.Exp) FROM Inventory)));
but it returns only one record with the nearest date. I've also tried selecting min in the total row but it returns all records.
I assume there's a workaround with 2 queries, one selecting unique ID with multiple LOTs and dates, the second returning the LOT of the nearest date from the first one. But if there is a way, I would like to do it all in one query.
Thank you for reading and have a good day.