Is this the correct syntax for SQLite for making nulls appear last?

后端 未结 3 529
北恋
北恋 2021-01-05 17:36
select * from table1
order by case Language when null then 1 else 0 end, Language

No matter which way I play around with it, it always displays nul

3条回答
  •  伪装坚强ぢ
    2021-01-05 17:45

    This is an extension of LS_dev's answer to UNIONs. Not a nice way, but I can't figure out any other way to make it work, since the documentation says:

    if the SELECT is a compound SELECT, then ORDER BY expressions that are not aliases to output columns must be exactly the same as an expression used as an output column.

    select * from (
        SELECT * FROM table1 -- but this select can have union in it
    ) ORDER BY Language IS NULL or Language = '', Language
    

提交回复
热议问题