Create a subset of the data with companies with zero deadlines and leaving them in your super set. Any entries in the 2nd table that are not null, you want to display as null, so use the case statement.
This works because our external table (A) returns
CO TERM_DT 1 7/15/2013 2 6/1/2015
But then our LEFT connection in our inline view also adds B.Co ...
CO TERM_DT B.CO 1 7/15/2013 1 2 6/1/2015 NULL
So you can see that we want to display NULL when B.CO is not null and not max (TERM_DT), will give the desired results. This is done using the case statement.
SELECT A.Co, Case when B.CO is not null then Max(A.Term_DT) else NULL end as Term_DT FROM tableName A LEFT JOIN (SELECT Distinct CO from tableName where Term_dt is null) B on A.Co = B.CO GROUP BY CO
source share