mysql order by, null first, and DESC after

前端 未结 2 1595
旧巷少年郎
旧巷少年郎 2020-12-04 14:58

How can I order DESC by a field, but list the NULL values first?

So I\'m having a table:

reuestId | offerId | offerTitle
1        | 1       | Alfa
NU         


        
相关标签:
2条回答
  • 2020-12-04 15:37
    SELECT *
    FROM TableX
    ORDER BY (requestId IS NOT NULL)
           , requestId DESC
    
    0 讨论(0)
  • 2020-12-04 15:47

    Try this:

    ORDER BY [reuestId] IS NULL DESC, [reuestId] DESC
    

    should work (for mySql)

    0 讨论(0)
提交回复
热议问题