A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

bring related fields into a query that uses MaxofDate and GROUP BY



 
 
Thread Tools Display Modes
  #1  
Old October 20th, 2008, 10:08 PM posted to microsoft.public.access.queries
Jey
external usenet poster
 
Posts: 27
Default bring related fields into a query that uses MaxofDate and GROUP BY

Oops, one more complication that I hadn't forseen. In my first query I only
needed the date of the last locate... but if I want the location (lat/long),
then I also need the specific loacte on that date... there can be more than
one locate per day. I have a Time field, but I'm having trouble even
incorporating that extra field to the query. When I try:
SELECT GPSLocations.Individual_ID, Max(GPSLocations.Date) AS MaxOfDate,
Max(GPSLocations.Time) AS MaxOfTime
FROM GPSLocations
GROUP BY GPSLocations.Individual_ID;

I get one record per Individual (which is what I want) with the date of the
last locate (good so far...) but with the "latest time of day" that the
individual was located... not the last time it was located on the last day.
How do I constrain the MaxOfTime clause to "MAxofTime where Date = MaxofDate"
?

Jey


"Jey" wrote:

Hi,
Thanks in advance if someone can show me how to do this!

I'm storing GPS collar data for radio-collared animals.
My table is called GPSLocations, and has fields:
GPS_ID
Individual_ID
Date
LatWGS84
LongWGS84
(plus more that don't apply to this problem)

I have a query to extract the last GPS locate date for each individual:
SELECT GPSLocations.Individual_ID, Max(GPSLocations.Date) AS MaxOfDate
FROM GPSLocations
GROUP BY GPSLocations.Individual_ID;

...but I want to modify it to also show the lat/long of that locate.

I've looked at: http://www.mvps.org/access/queries/qry0020.htm
but my query is complicated by also having a GROUP BY clause.

I've tried things like:
SELECT Q.Individual_ID, Q.Date, Q.LatWGS84, Q.LongWGS84
FROM GPSLocations As Q
WHERE Q.Date = (SELECT T.Individual_ID, Max(T.Date) AS MaxofDate
FROM GPSLocations As T
WHERE T.GPS_ID = Q.GPS_ID
GROUP BY T.Individual_ID)
GROUP BY Q.Individual_ID;

I just can't get it to work! Is it even possible to do in one query, or will
I have to use more than one?

Jey



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:32 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.