Skip to content
Advertisement

Oracle – Selecting record based on latest date

In this query, in the ODF_CA_NL_INIT_REQ_NOTE n table, there can be multiple NL_NOTEs per each record in the ODF_CA_OTHER o table. One to many relationship.

I want to select the n.NL_NOTE for each record with the latest n.LAST_UPDATED_DATE.

I added the subselect as seen below, but for each record returned in the query, the NOTE field is just showing the latest n.NL_NOTE from the entire ODF_CA_NL_INIT_REQ_NOTE n table.

How do I show, for each record returned in the query, the latest n.NL_NOTE for each related record and not for the entire table?

Thanks

Advertisement

Answer

One way to do it is analytic function with first/last option:

dbfiddle

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