Skip to content
Advertisement

Need to filter all rows in postgres where records share a common id but any one fails to pass a subquery

I have a table in Postgres that looks something like this:

The algorithm is if any single record has reversed = true or status = foo, all records with the same group_id should be filtered. If group_id is null, which is possible, I’d like to keep those records regardless of reversed or status

The closest I’ve gotten is with a NOT IN subquery:

but NOT IN also filters nulls naturally which i don’t want. have also tried not exists and inner joins but haven’t quite gotten the right syntax. any help would be greatly appreciated!

Advertisement

Answer

Try the following by adding group_id is null in where condition,

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement