Sahar Alsadah
Sahar Alsadah

Reputation: 2720

Oracle Select Query Specific Case

Say I got below table,

Col1 Col2 Col3
Apple Yes 1
Banana No 2
Orange Yes 3
Apple Yes 4
Apple Yes 5
Apple Yes 6
Banana No 7

I want to make a query that selects the fruits that have only "No" as a value for col2. In this case it's 'Banana'.

Thanks

Upvotes: 1

Views: 47

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269853

You can use a having clause. Using the fact that 'Yes' > 'No':

select fruit
from t
group by fruit
having max(col2) = 'No';

Upvotes: 2

Related Questions