Skip to content
Advertisement

How to select and join field with max date?

I have two tables joined on RECID and AAATRANSPORTORDERRECID :

AAATRANSPORTTABLE

AAALTLCHANGEREQUEST

I need to select the record shown from AAATRANSPORTTABLE and join the AAALTLCHANGEVALUE value for the most recent CREATEDDATETIME from AAALTLCHANGEREQUEST. My query is as below:

It produces these results:

My desired output is

Advertisement

Answer

The problem is you are selecting max(l.CREATEDDATETIME) in your select query but you are not doing anything to select the max date in your where clause. You have to put a where clause to select the row with max date out of your 3 rows. I have tried to modify your query, you might need to modify the table and column name but you will get the context once you go through it –

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement