select * from ( select organisation_code ,ref_correlation_id ,batch_received_batch_id ,event_rr_id ,EVENT_RR_LOCAL_REF_ID ,EVENT_OPERATION_ID ,EVENT_RR_TRANS_TS ,max(EVENT_RR_TRANS_TS) over (partition by organisation_code, EVENT_RR_LOCAL_REF_ID) as maxTS from NPF.npf_event_referral_received where organisation_code in ('G00037-F', 'G00035-B') and EVENT_OPERATION_ID <> 3 ) RR where EVENT_RR_TRANS_TS = maxTS