Skip to content
Advertisement

PostgreSQL cross join using max returns null

I want to select the max() value of the modified_at column in each of several tables:

This works correctly as long as each of the tables has at least 1 row. The problem is that when just one of the tables has 0 rows, null is returned for all tables:

What is a solution that returns the correct values for the tables that do have rows? PostgreSQL-10

Advertisement

Answer

Using OUTER JOINs should do it

but a possibly simpler option would be to use 3 subqueries instead:

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