Q:

How do I not select a row from sets with null and not null in SQL?

I have tried to find this on SO.
I have a table,
id   | col2 | col3
----   ----   ----
5     smith   (null)
5     smith  100
12    Jackson 356
12    Jackson 400
8     Johnson (null)
9     bob     1200

In this scenario I only want the rows from a set where the same id only has one non-null.  In other words, I don't want smith, I don't want Johnson.  I only want Jackson and bob.
I have tried,
select * from table 
where is not null a
nd not exists (select * from table where is null)

I can't get it to work.

A:

You can use NOT EXISTS but include a WHERE to reference each id:
select * 
from yourtable t
where col3 is not null 
  and not exists (select id 
                  from yourtable d
                  where d.col3 is null
                   and t.id = d.id);

See Demo

