Em um modo mais simples e pratico: with cte as ( select usuario_id , row_number () over ( partition by usuario_id order by usuario_id ) as r from creditos where status = 0 ) delete cte where r > 1 ;