Skip to content
Advertisement

Postgres: How to make NULL friendly MIN filtering in Having clause?

audit_table might contain repeated userId.

We have following SQL query

updatedDate field might be null and for case when all rows in audit_table for concrete userId contains only nulls I don’t see these rows but I want. Is there way to acheve it ?

Advertisement

Answer

One method is an explicit comparison:

Another method is to count the updatedDates that are less than ? or NULL:

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