Skip to content
Advertisement

Postgres group by empty string question to include empty string in output

I have following table in Postgres

Tried this

Need this ouput for each phone where there is empty string for missing group.

Advertisement

Answer

You need a CTE which returns all possible combinations of phone and group and a left join to the table so you can group by phone:

See the demo.
Results:

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