Avatar of SOUTHAMERICA70
SOUTHAMERICA70

asked on 

Query on the latest date

I wanted to only show the latest date  in my query...I have multiple lines that are the same but wanted to only show the latest date in EPD_STATUS_CHANGE_TS field.

Here is my SQL statement:

SELECT BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_IDENTIFIER, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_SEQUENCE_IDENTIFIER, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_REVISION_LEVEL, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.SOURCE_START_TS, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.AIRCRAFT_IDENTIFICATION, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.LINE_NUMBER, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.MAJOR_MODEL, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.INSPECTED_AP_LINE_NUMBER_TXT, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.INSPECTED_AP_MAJOR_MODEL, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_STATUS, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_STATUS_CHANGE_TS, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_STATUS_CHANGE_TS_TZ_IX, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_CREATE_TS, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_CREATE_TS_TZ_IX
FROM BCDW_PROD_V_VL_CAPTURE_CONTROL_V;
Microsoft Access

Avatar of undefined
Last Comment
GRayL
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

DO you want to continue to show each record, but all of them to show the latest date? or do you want to show just the latest record for each unique combination of all the fields you've listed?  (or something else?)
Avatar of SOUTHAMERICA70
SOUTHAMERICA70

ASKER

Unique record based in EPD _IDENTIFIER.
Avatar of SOUTHAMERICA70

ASKER

Sorry ...use this SQl statement instead.

SELECT BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_IDENTIFIER, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.LINE_NUMBER, BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_STATUS, BCDW_PROD_V_VL_EPD_STAGE_ACTION_V.STAGE_NAME, BCDW_PROD_V_VL_EPD_STAGE_ACTION_V.STAGE_STATUS, BCDW_PROD_V_VL_EPD_STAGE_ACTION_V.STATUS_CHANGE_TS, BCDW_PROD_V_VL_EPD_STAGE_ACTION_V.CURRENT_WORK_CENTER
FROM BCDW_PROD_V_VL_CAPTURE_CONTROL_V LEFT JOIN BCDW_PROD_V_VL_EPD_STAGE_ACTION_V ON BCDW_PROD_V_VL_CAPTURE_CONTROL_V.EPD_IDENTIFIER = BCDW_PROD_V_VL_EPD_STAGE_ACTION_V.EPD_IDENTIFIER;
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Create a saved query that gives you the record with the latest date and then use that saved query instead of BCDW_PROD_V_VL_CAPTURE_CONTROL_V in your main query.

One version of the  saved query would be..

Select T.* from BCDW_PROD_V_VL_CAPTURE_CONTROL_V as T
Inner join
(Select EPD _IDENTIFIER, Max(EPD_STATUS_CHANGE_TS) as mdate from BCDW_PROD_V_VL_CAPTURE_CONTROL_V
group by EPD _IDENTIFIER) as q1
on t.EPD _IDENTIFIER= qry1.EPD _IDENTIFIER and t.EPD_STATUS_CHANGE_TS    = qry1.mdate
Avatar of SOUTHAMERICA70

ASKER

Don't get it.....
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you mean it doesn't work or do you mean you don't understand why you have to do this?
Avatar of SOUTHAMERICA70

ASKER

Do not understand what to do with this.....
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

You existing query looks like it is built in the query grid.

You say you want to see only one record for each unique value of EPD _IDENTIFIER and that record should be the record with the latest date in EPD_STATUS_CHANGE_TS.

The query I posted selects the record with the latest date.
Select T.* from BCDW_PROD_V_VL_CAPTURE_CONTROL_V as T
Inner join
(Select EPD _IDENTIFIER, Max(EPD_STATUS_CHANGE_TS) as mdate from BCDW_PROD_V_VL_CAPTURE_CONTROL_V
group by EPD _IDENTIFIER) as q1
on t.EPD _IDENTIFIER= qry1.EPD _IDENTIFIER and t.EPD_STATUS_CHANGE_TS    = qry1.mdate

You need to paste this into the sql view of a new query and save it.
When you run this query you should get one record for each value of EPD _IDENTIFIER .

You now need to use this saved query in your main query instead of using the table BCDW_PROD_V_VL_CAPTURE_CONTROL_V

(if you then get multiple records for each EPD _IDENTIFIER you have to look at the other tables you are using and the joins you are using in the complete query.).
EPD _IDENTIFIER
ASKER CERTIFIED SOLUTION
Avatar of GRayL
GRayL
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of GRayL
GRayL
Flag of Canada image

Thanks, glad to help.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo