This approach uses aggregation to find all id
s that have both values. This is used as an exclusion list using a left outer join
:
select *
from table t left outer join
(select id
from table t
group by t.id
having sum(case when comment = 'apple' then 1 else 0 end) > 0 and
sum(case when comment = 'orange' then 1 else 0 end) > 0
) toexclude
on t.id = toexclude.id
where toexclude.id is null;