Skip to content
Advertisement

How to do NULLS LAST in SQLite?

I’d like to sort my result with all NULL columns last (NULLS LAST), as specified in the SQL:2003 extension T611. Sadly, SQLite seems to not support it. Is there a clever workaround?

Advertisement

Answer

could this work?

SELECT ....... ORDER BY COALESCE(col1,col2,col3,etc) IS NULL

I am kind of confused by your wording “all NULL columns last”. If you want all NULL values last in a particular column, use this:

SELECT ....... ORDER BY col1 IS NULL
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement