C
Carl Rapson
I have four fields that define my primary key - the first 3 are text fields,
and the 4th is a number which isn't necessarily sequential, but does
increase by some amount in each succeeding record. I need to retrieve the
record where the 4th field is equal to the next-to-highest value of all
records matching the first 3 fields. I've tried the following:
SELECT [Field 1],[Field 2],[Field 3],Max([Field 4]) AS [Previous Value]
FROM [My Table] AS A
GROUP BY [Field 1],[Field 2],[Field 3]
HAVING Max([Field 4]) <
(SELECT Max([Field 4]) FROM [My Table] AS B WHERE B.[Field 1]=A.[Field 1]
AND B.[Field 2]=A.[Field 2] AND B.[Field 3]=A.[Field 3]);
But that doesn't seem to work - it returns no records, when I know for
certain that there are records.
Does anyone have any suggestions as to how to approach this query?
Thanks for any assistance,
Carl Rapson
and the 4th is a number which isn't necessarily sequential, but does
increase by some amount in each succeeding record. I need to retrieve the
record where the 4th field is equal to the next-to-highest value of all
records matching the first 3 fields. I've tried the following:
SELECT [Field 1],[Field 2],[Field 3],Max([Field 4]) AS [Previous Value]
FROM [My Table] AS A
GROUP BY [Field 1],[Field 2],[Field 3]
HAVING Max([Field 4]) <
(SELECT Max([Field 4]) FROM [My Table] AS B WHERE B.[Field 1]=A.[Field 1]
AND B.[Field 2]=A.[Field 2] AND B.[Field 3]=A.[Field 3]);
But that doesn't seem to work - it returns no records, when I know for
certain that there are records.
Does anyone have any suggestions as to how to approach this query?
Thanks for any assistance,
Carl Rapson