Add another item #3 to just the "good" group, the outer
join method you're using will return a group id for that one as well,
which your "null" check will filter out.
That was actually an error in my description. I meant to say that I am
looking for things that are not in a Good group (rather than things
that are not in a Bad group, which is what I actually said). That's
why I was joining against Good groups and looking for things whose
group id is null. So, the original query would be correct to filter
out item #3 here.
Anyway, I hadn't known about this Not Exists technique. I changed my
queries around to use that and it is actually faster than before and
my SQLA code is a lot clearer using not_() and .any() than it was with
chained joins and select_from, so this is a great solution. This is
very helpful for me because I have run into variations of this in the
past and never been sure how to build the best query. Thanks!