Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max date off of 1 table Multiple fields 1

Status
Not open for further replies.

John1Chr

Technical User
Joined
Sep 24, 2005
Messages
218
Location
US
I would like to grab the Nickname off of Table 1 where the EFFDT is the greatest - (ie. Sue was the nickname on 7/1/2012.) I want to show the fields Person nickname and effdt. I'm thinking this is fairly simple but can't seem to figure out.


Person NickName Status EFFDT
Susan Susie A 01-Jan-01
Susan Sue A 01-Jul-12
 

One way to do it:
Code:
Select * From MyTable
Where EFFDT = ([blue] Select Max(EFFDT) From MyTable[/blue])
You may need some #'s around the date....

Have fun.

---- Andy
 
It looks like it is working for the ones that have a double. The ones that only have one date are being ignored.
 

Is you problem solved? Or do you need any additional help?

If you do need more help, please provide a better example of your data and the outcome you hope to get.

Have fun.

---- Andy
 
I apologize, if there is a Kevin with just one efft date that gets ignored.
 
Code:
Select * From MyTable
Where EFFDT = ( Select Max(EFFDT) From MyTable)
GROUP BY Name


Randy
 
Try add the Person field into the subquery:
Code:
Select * 
From MyTable
Where EFFDT = (Select Max(EFFDT) From MyTable M WHERE M.Person = MyTable.Person)

Duane
Hook'D on Access
MS Access MVP
 
Thanks,

You both helped me solve. In the end I used the Last to get the latest Nickname. Here was the final SQL that works:

SELECT PERSON_TBL.PERSON, Max(PERSON_TBL.EFFDT) AS MaxOfEFFDT, Last(PERSON_TBL.NICKNAME) AS LastOfNICKNAME
FROM PERSON_TBL
GROUP BY PERSON_TBL.PERSON;
 
It appears to work...it is grabbing the one with the latest EFFDT. Is there a safer or better method?
 
You didn't respond to my suggestion. Did it work? If not, what results were wrong?

Do you have some actual table and field names and more sample records?

Duane
Hook'D on Access
MS Access MVP
 
Duane,

You were correct. Where the field has the same name it doubled up with the Last Command when I tried to link to.
 
I'd try this:
Code:
SELECT A.PERSON, A.EFFDT, A.NICKNAME
FROM PERSON_TBL A INNER JOIN (
SELECT PERSON, Max(EFFDT) AS MaxOfEFFDT FROM PERSON_TBL GROUP BY PERSON
) L ON A.PERSON=L.PERSON AND A.EFFDT=L.MaxOfEFFDT

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV....Dhookum's worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top