Skip to content
Advertisement

GROUP BY – do not group NULL

I’m trying to figure out a way to return results by using the group by function.

GROUP BY is working as expected, but my question is: Is it possible to have a group by ignoring the NULL field. So that it does not group NULLs together because I still need all the rows where the specified field is NULL.

So now let’s say I have 5 rows and the ancestor field is NULL, it returns me 1 row….but I want all 5.

Advertisement

Answer

Perhaps you should add something to the null columns to make them unique and group on that? I was looking for some sort of sequence to use instead of UUID() but this might work just as well.

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