select a.cid, a.cinmate_number, ; b.cinmates_id, b.ttxndatetm, b.txnstatus ; from INMATES a ; inner join ACCT_EVENTS b ; on a.cid = b.cinmates_id ; where b.txnStatus= 'OPEN' AND ttoc(b.ttxndatetm,1) = ; (select max(ttoc(ttxndatetm,1)) from ACCT_EVENTS c ; where b.cinmates_id = c.cinmates_id)PS: Do not undertake ttoc() usage when comparing datetimes. It's purposefully there.