Skip to content
Advertisement

Rows with multiple corresponding values in the same table

Suppose I have a table

Name          Wear
Martin        Hat
Martin        ?
Martin        Shirt
Alfred        Tee
Alfred        Jeans

And I only want names of people whose Wear value is fully given, that is without a NULL (?) value in there.

I thought about using a group by … having Wear <> NULL but this isn’t sufficient, as there can be more than one Wear value.

In this case, I would like to only return ‘Alfred’.

Advertisement

Answer

You can do it like

HAVING SUM(Wear IS NULL) = 0

or

HAVING COUNT(*) = COUNT(Wear)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement