Dê uma chance a isso: SELECT ID, case when MAX(DATE IS NULL) = 0 THEN max(DATE) END AS DATE FROM test GROUP BY ID;