Phito Phito - 6 months ago 23
SQL Question

group by having no null values in a column

If I execute the following query

select a, bar.c from foo
left join bar on =

I get theses results

a c
1 1
1 3
1 null

2 1
2 2

3 1
3 null
3 3
3 4

Now I would like to group theses values by
, but only when there is not a single null value for
, to only get a=2 as a result. How would I do that?

Answer Source

You can use having:

select a
from foo left join
     on =
group by a
having count(*) = count(bar.c);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download