Please can someone assist with writing a CTE for the following scenario?
I have the following query:
SELECT
PEA.tblPARTY_PERSON
,PEA.PEAS_STATUS_DATE
,EAS.EAS_DESC
FROM
tblLU_EOTAS_APPLIC_STATUS EAS
INNER JOIN tblPARTY_PERSON_EOTAS_APPLIC_STATUS PEA
ON EAS.EAS_ID = PEA.tblLU_EOTAS_APPLIC_STATUS
WHERE PEA.tblPARTY_PERSON = 62649
ORDER BY PEA.PEAS_STATUS_DATE DESC
Which returns the following data:
For each Party_ID
I need to return only the most recent date and corresponding data in the EAS_DESC
column (I have used a WHERE
clause in the SQL above to reduce the data output to just one record for convenience/testing, but will need to remove this in the final script). I'd like to use a CTE but am not sure how best to write it, please help!
Thanks in advance.