Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...It is good to know that there are groups such as this willing to share knowledge in this money driven economy..."

Geography

Where in the world do Tek-Tips members come from?
John1Chr (TechnicalUser)
15 Feb 12 13:23
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
 
Andrzejek (Programmer)
15 Feb 12 13:33
   
One way to do it:

CODE

Select * From MyTable
Where EFFDT = ( Select Max(EFFDT) From MyTable)
You may need some #'s around the date....

Have fun.

---- Andy

John1Chr (TechnicalUser)
15 Feb 12 14:02
It looks like it is working for the ones that have a double.  The ones that only have one date are being ignored.
Andrzejek (Programmer)
15 Feb 12 15:08
   
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

John1Chr (TechnicalUser)
15 Feb 12 16:04
I apologize, if there is a Kevin with just one efft date that gets ignored.  
randy700 (Programmer)
15 Feb 12 16:08

CODE

Select * From MyTable
Where EFFDT = ( Select Max(EFFDT) From MyTable)
GROUP BY Name
 

Randy

dhookom (Programmer)
15 Feb 12 16:58
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

John1Chr (TechnicalUser)
16 Feb 12 7:49
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;
 
dhookom (Programmer)
16 Feb 12 8:51
I would never rely on LAST to return the correct value.  

Duane
Hook'D on Access
MS Access MVP

John1Chr (TechnicalUser)
16 Feb 12 9:03
It appears to work...it is grabbing the one with the latest EFFDT.  Is there a safer or better method?
Helpful Member!  dhookom (Programmer)
16 Feb 12 9:54
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

John1Chr (TechnicalUser)
16 Feb 12 11:51
Duane,

You were correct.  Where the field has the same name it doubled up with the Last Command when I tried to link to.
PHV (MIS)
17 Feb 12 5:20
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: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

John1Chr (TechnicalUser)
17 Feb 12 18:54
Thanks PHV....Dhookum's worked.  

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close