select * from detector_cache , (select count(*) countSensorParts from detector where sensor_id=119) tmp, (select count(*) countSensorPartsCache from detector_cache where sensor_id=119 and TO_CHAR(measure_date,'dd.mm.YYYY HH:MI')='28.12.1983 08:30') tmp2 where sensor_id=119 and TO_CHAR(measure_date,'dd.mm.YYYY HH:MI')='28.12.1983 08:30' and tmp.countSensorParts=tmp2.countSensorPartsCache+1;