Solved

I need to see only the latest record in an address book table.

Posted on 2011-09-21
12
713 Views
Last Modified: 2012-05-12
I am working on a query to clean up our JD Edwards address book table. The ALAN8 field is the unique, numeric, Associate address number (primary key). The ALUPMJ field is a 6-digit, numeric, Julian date field.

The F0116 table can have multiple entries for each individual associate (ALAN8) based upon the last date something in the table was updated (ALUPMJ).

I only want to see a single record for each Address Number (ALAN8) based upon on the last updated date (ALUPMJ). I have been scratching my head trying different functions, such as MAX, but I continue to see multiple records listed for each employee number. How should I modify my query in order to see only the last modified record per associate number regardless of the number of modifications in the remaining fields?
_____________________________________________________________________________
      Table F0116
Field      Description      Type      Length
      ALAN8      Address Number      Numeric      8
      ALEFTB      Date - Beginning Effective      Date      6
      ALEFTF      Effective Date Existence (1/0)      Character      1
      ALADD1      Address Line 1      String      40
      ALADD2      Address Line 2      String      40
      ALADD3      Address Line 3      String      40
      ALADD4      Address Line 4      String      40
      ALADDZ      Postal Code      String      12
      ALCTY1      City            String      25
      ALCOUN      County            String      25
      ALADDS      State            String      3
      ALCTR      Country            String      3
_____________________________________________________________________________      

SQL View of Query:
SELECT PRODDTA_F0116.ALAN8, Max(PRODDTA_F0116.ALUPMJ) AS MaxOfALUPMJ, PRODDTA_F0116.ALADD1, PRODDTA_F0116.ALADD2, PRODDTA_F0116.ALADD3, PRODDTA_F0116.ALADD4, PRODDTA_F0116.ALCTY1, PRODDTA_F0116.ALCOUN, PRODDTA_F0116.ALADDS, PRODDTA_F0116.ALADDZ, PRODDTA_F0116.ALCTR
FROM PRODDTA_F0116
GROUP BY PRODDTA_F0116.ALAN8, PRODDTA_F0116.ALADD1, PRODDTA_F0116.ALADD2, PRODDTA_F0116.ALADD3, PRODDTA_F0116.ALADD4, PRODDTA_F0116.ALCTY1, PRODDTA_F0116.ALCOUN, PRODDTA_F0116.ALADDS, PRODDTA_F0116.ALADDZ, PRODDTA_F0116.ALCTR
ORDER BY Max(PRODDTA_F0116.ALUPMJ) DESC;
_____________________________________________________________________________      

I have included a screen shot ss an example using a single ALAN8 that has three (3) records. I only want to see the latest Julian date, 107109.  

Thanks in advance for your assistance.

TW

 Screen Shot Of Executed Query for a Single ALAN8
0
Comment
Question by:Tom Winslow
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
Can you post the database, or a cut-down version of it?  Most likely the problem is that (apart from the Date field) there is unique data in some records, thus preventing you from seeing just the record with the most recent date.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
You might need to create a separate query to get the unique ID of the record with the most recent date, and then use the ID to filter the form or subform for just that record.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
try this query

select * from F0116
where ALUPMJ in (select max([ALUPMJ]) from F0116 as F where F.ALAN8=F0116.ALAN8)
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
Try this:

SELECT *
FROM F0116 AS A

WHERE ALUPMJ = (SELECT MAX (ALUPMJ) FROM F0116 WHERE A.ALAN8 = ALAN8 GROUP BY ALAN8)
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
this shuld run faster


SELECT  T.*
FROM
    PRODDTA_F0116  AS T
 INNER JOIN
       (SELECT
             Max(T2.[ALUPMJ]) as MaxALUPMJ, [ALAN8]
         FROM
             PRODDTA_F0116  T2  
             Group By T2.ALAN8
        ) T1
ON  T.[ALUPMJ]=T1.MaxALUPMJ and T.ALAN8=T1.ALAN8


0
 

Author Comment

by:Tom Winslow
Comment Utility
I have been requested to upload a portion of the table. Please see attached.
tblF0116Project.csv
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
Tom,

you uploaded an incomplete file..

where is column for ALUPMJ ?

have you tried the query i posted at http:#a36574475 ?
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
There is no date field at all and no field called ALUPMJ.
0
 

Author Comment

by:Tom Winslow
Comment Utility
OOPS! Uploading another file.
tblF0116Project.csv
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
test this, run query1



DB-Q-27319964.mdb
0
 

Author Comment

by:Tom Winslow
Comment Utility
I am experimenting with the answers and will get back as soon as possible.
0
 

Author Closing Comment

by:Tom Winslow
Comment Utility
Thanks. I learned a lot from studying this query.

tw
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now