Skip to content
Advertisement

SQLite: Order by number of NULL values

In SQLite, is there any way of ordering by the number of NULL values in each row, without having stored this number explicitly in a separate column?

Something like

Advertisement

Answer

You can count the number of null values in the row in the order by clause, like so:

Condition (column_1 is null) evaluates as 1 if the column is null, else 0.

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