Hi, I have a data table that looks like the following: -
fld_ID, fld_Foreign, fld_Date
12, 174, 17/12/2010
13, 174, 07/01/2011
14, 174, 12/01/2011
15, 174, 20/02/2011
16, 174, 28/02/2011
17, 174, 15/12/2010
18, 174, 07/01/2011
19, 174, 17/12/2010
20, 192, 31/01/2011
21, 192, 28/02/2011
22, 185, 01/12/2010
23, 192, 11/03/2011
24, 192, 11/01/2011
43, 195, 21/01/2011
44, 195, 28/01/2011
45, 195, 14/02/2011
46, 195, 28/02/2011
47, 195, 01/03/2011
48, 195, 20/03/2011
49, 195, 05/04/2011
50, 195, 20/01/2011
I am trying to return the last fld_ID before today grouped by fld_Foreign. So the results would look something like the following: -
fld_ID
14
22
24
43
The records are not always entered in chronological order, so this means I can't use the LAST function, and I tried using an extra query inbetween that is sorted by date so that the records appear in chronological order, but the LAST function still seems to pick up the records in the order from the main table. selecting only dates that occur before today is easy enough, likewise with the grouping on fld_Foreign. What I thought would be a very straight forward query is really starting to annoy me now. I am using MS Access 97.
Ben
fld_ID, fld_Foreign, fld_Date
12, 174, 17/12/2010
13, 174, 07/01/2011
14, 174, 12/01/2011
15, 174, 20/02/2011
16, 174, 28/02/2011
17, 174, 15/12/2010
18, 174, 07/01/2011
19, 174, 17/12/2010
20, 192, 31/01/2011
21, 192, 28/02/2011
22, 185, 01/12/2010
23, 192, 11/03/2011
24, 192, 11/01/2011
43, 195, 21/01/2011
44, 195, 28/01/2011
45, 195, 14/02/2011
46, 195, 28/02/2011
47, 195, 01/03/2011
48, 195, 20/03/2011
49, 195, 05/04/2011
50, 195, 20/01/2011
I am trying to return the last fld_ID before today grouped by fld_Foreign. So the results would look something like the following: -
fld_ID
14
22
24
43
The records are not always entered in chronological order, so this means I can't use the LAST function, and I tried using an extra query inbetween that is sorted by date so that the records appear in chronological order, but the LAST function still seems to pick up the records in the order from the main table. selecting only dates that occur before today is easy enough, likewise with the grouping on fld_Foreign. What I thought would be a very straight forward query is really starting to annoy me now. I am using MS Access 97.
Ben
Last edited: