Return column 1 only if column 2 is NULL in all rows with the same column 1

Art :

I'm sure this is SQL-101 but I can't figure it out nor can I come up with the correct verbiage to find any useful results in web searches.

Example table:

id      ext             nr
289979  111-000-1002    529
392959  111-000-1002    NULL
449707  111-000-1002    335
400151  999-555-1212    NULL
456902  999-555-1212    NULL
471001  999-555-1212    NULL

I am trying to format a query to return the ext if the nr on all rows is NULL so the query would return 999-555-1212 but not 111-000-1002.

Gordon Linoff :

Is this what you want?

select ext
from t
group by ext
having max(nr) is null;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11879&siteId=1