SELECT t.idFROM t_staff t left join (select * from (select b.*, (row_number() over (partition by STAFF_ID order by CREATED_AT desc)) px from R_STAFF_PLAN b) e where px = 1) rsp on t.id = rsp.STAFF_ID