sqlsortingsql-order-bysql-null

Make nulls come last when sorting ascending


I have a SQL table with a datetime field that can be null.

What is a simple way to sort query results ascending by datetime, but with rows where datetime is null at the end, not at the beginning?


Solution

  • select MyDate
    from MyTable
    order by case when MyDate is null then 1 else 0 end, MyDate