SELECT * FROM( SELECT INS.ANIMAL_ID, INS.NAME FROM ANIMAL_INS INS LEFT JOIN ANIMAL_OUTS OUTS ON INS.ANIMAL_ID = OUTS.ANIMAL_ID WHERE OUTS.ANIMAL_ID IS NOT NULL ORDER BY OUTS.DATETIME - INS.DATETIME DESC ) WHERE ROWNUM < 3;