Regarding the original request, try
NOT ( EXISTS( Select analyzed.UnitID FROM analyzed WHERE [NotHeard].UnitID = analyzed.UnitID) AND EXISTS( Select analyzed2.UnitID FROM analyzed2 WHERE [NotHeard].UnitID = analyzed2.UnitID) )
which would mean both. But this corresponds to what you initially (tested on sample data). Are you sure you do not mean not in neither B? It will be
NOT ( EXISTS( Select analyzed.UnitID FROM analyzed WHERE [NotHeard].UnitID = analyzed.UnitID) OR EXISTS( Select analyzed2.UnitID FROM analyzed2 WHERE [NotHeard].UnitID = analyzed2.UnitID) )
Understand that the EXISTS solution uses correlated subqueries, which can be worse than LEFT JOIN and NULL, here's a sample.
SELECT NotHeard.UnitID, NotHeard.Address FROM (NotHeard LEFT JOIN analyzed ON NotHeard.UnitID = analyzed.UnitID) LEFT JOIN analyzed2 ON NotHeard.UnitID = analyzed2.UnitID WHERE analyzed.UnitID Is Null OR analyzed2.UnitID Is Null GROUP BY NotHeard.UnitID, NotHeard.Address;
Note that I used OR in a state compared to the Austin solution, and would not have given you either in the analysis or in the analysis2.
source share