How to order by column with non-null values first in sql

后端 未结 3 1195
名媛妹妹
名媛妹妹 2020-12-31 03:48

I need to write a sql statement to select all users ordered by lastname, firstname. This is the part I know how to do :) What I don\'t know how to do is to order by non-nu

3条回答
  •  礼貌的吻别
    2020-12-31 04:06

    See Sort Values Ascending But NULLS Last

    basically

    SELECT *
        FROM @Temp
        ORDER BY CASE WHEN LastName IS NULL THEN 1 ELSE 0 END, LastName
    

提交回复
热议问题