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  

max for each person



 
 
Thread Tools Display Modes
  #1  
Old December 20th, 2009, 05:00 AM posted to microsoft.public.access.queries
geebee
external usenet poster
 
Posts: 87
Default max for each person

hi,

need to select the MAX centername for each person (determined by combining
date. and centername AS ID) , and join that to another table by the created
ID. the 2 tables will be joined on the created ID. there are more than one
centername for each person. but i want the most recent one to be selected
and then used as a subquery in a main query. just not sure the syntax to do
this, or best approaches.

thanks in advance,
geebee

  #2  
Old December 20th, 2009, 06:34 AM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default max for each person

Use a subquery to restrict it to the particular record that matches the
person and most recent date.

Without knowing your schema, it will be this kind of thing:

SELECT ID, PersonID, CentreName
FROM Table1
WHERE ID = (SELECT TOP 1 ID
FROM Table1 AS Dupe
WHERE Table1.PersonID = Dupe.PersonID
ORDER BY Dupe.TheDate DESC, ID DESC);

If subqueries are new, see:
http://allenbrowne.com/subquery-01.html

More examples:
http://www.mvps.org/access/queries/qry0020.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"geebee" (noSPAMs) wrote in message
...
hi,

need to select the MAX centername for each person (determined by combining
date. and centername AS ID) , and join that to another table by the
created
ID. the 2 tables will be joined on the created ID. there are more than one
centername for each person. but i want the most recent one to be selected
and then used as a subquery in a main query. just not sure the syntax to
do
this, or best approaches.

thanks in advance,
geebee

 




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 12:21 AM.


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