Query Question:
This :
SELECT tblAttendancePoints.[EmpID], Max(tblAttendancePoints.PointsDate) AS MaxOfPointsDate, tblAttendancePoints.Total
FROM tblAttendancePoints
GROUP BY tblAttendancePoints.[EmpID], tblAttendancePoints.Total
HAVING (((tblAttendancePoints.[EmpID])=179709));
Returns:
EmpID MaxOf
Points Date Total
179709 1/30/2007 0
179709 3/20/2007 1.5
179709 6/6/2007 3
179709 6/8/2007 4.5
I want to return the last record. (6/8 - 4.5)
Seems annoyingly simple…
But when I do this:
SELECT tblAttendancePoints.[EmpID], Max(tblAttendancePoints.PointsDate) AS MaxOfPointsDate, Last(tblAttendancePoints.Total) AS LastOfTotal
FROM tblAttendancePoints
GROUP BY tblAttendancePoints.[EmpID]
HAVING (((tblAttendancePoints.[EmpID])=179709));
I get:
EmpID MaxOf
Points Date LastOf
Total
179709 6/8/2007 3
I know this has got to be really obvious…but I don't get it.
Query Properties are all default. No parameters set other than [EmpID] = 179709 to minimize the return.
The only wacky thing I can think of is that this table has a 3 field primary key on EmpID, PointsDate, CalcReason which is probably poor design.
I can (painfully) restructure the table if I know this will help.
Any suggestions?
Thanks,
Tom
This :
SELECT tblAttendancePoints.[EmpID], Max(tblAttendancePoints.PointsDate) AS MaxOfPointsDate, tblAttendancePoints.Total
FROM tblAttendancePoints
GROUP BY tblAttendancePoints.[EmpID], tblAttendancePoints.Total
HAVING (((tblAttendancePoints.[EmpID])=179709));
Returns:
EmpID MaxOf
Points Date Total
179709 1/30/2007 0
179709 3/20/2007 1.5
179709 6/6/2007 3
179709 6/8/2007 4.5
I want to return the last record. (6/8 - 4.5)
Seems annoyingly simple…
But when I do this:
SELECT tblAttendancePoints.[EmpID], Max(tblAttendancePoints.PointsDate) AS MaxOfPointsDate, Last(tblAttendancePoints.Total) AS LastOfTotal
FROM tblAttendancePoints
GROUP BY tblAttendancePoints.[EmpID]
HAVING (((tblAttendancePoints.[EmpID])=179709));
I get:
EmpID MaxOf
Points Date LastOf
Total
179709 6/8/2007 3
I know this has got to be really obvious…but I don't get it.
Query Properties are all default. No parameters set other than [EmpID] = 179709 to minimize the return.
The only wacky thing I can think of is that this table has a 3 field primary key on EmpID, PointsDate, CalcReason which is probably poor design.
I can (painfully) restructure the table if I know this will help.
Any suggestions?
Thanks,
Tom