View Single Post
  #5  
Old May 13th, 2010, 10:06 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default First function returning min

Sure, it would help if you were having a full date AND time field, rather
than a date and an AM/PM field.

Two queries is probably the easiest way to go:

SELECT IndividualID, MIN( [date] + iif( [AM/PM] = "PM", #12:00:00#, 0) ) AS
DateAndPseudoTime
FROM tableName
GROUP BY IndividualID

to be saved, as, say, q1, then


SELECT a.*
FROM tableName AS a INNER JOIN q1
ON a.IndividualID=q1.IndividualID
WHERE a.[date]+ iif( [AM/PM] ="PM", #12:00:00#, 0 ) = q1.DateAndPseudoTime

should return the desired result. Again, it would be easier with full date
AND TIME field, rather than two different fields which I assume were [date]
and [AM/PM])


For completeness, FIRST and LAST can be very useful if you wish to get data
from the same record:

SELECT f1, LAST(f2), LAST(f3) FROM somewhere GROUP BY f1

given that somewhere is:
f1 f2 f3
1 10 20
1 20 10
1 15 30
1 17 5

could return any of the four record (depends on the execution plan), while

SELECT f1, MIN(f2), MIN(f3) FROM somewhere GROUP BY f1
would return
1 10 5
where values come from different records! Same with using MAX(f2),
MAX(f3).


But definitively, First (and Last) do not mean earliest (latest), neither
TOP 1.


Vanderghast, Access MVP