select prod_id, status from (
select prod_id, status, row_number() over( partition by prod_id order by case status when 'Repaired' then 0 when 'damaged' then 1 else 2 end) myrownum
from tab1
)
where status='damaged' and myrownum=1;
awking00
select id, status from table where status = 'damaged"
minus
select id, "damaged" from table where status = 'Repaired"
select * from Products where prod_id not in (select prod_id from products where status='Repaired');