PHP, MYSQL: Order by date but empty dates last not first

前端 未结 5 2353
暗喜
暗喜 2021-02-19 19:30

I fetch an array with todo titles and due dates from MySQL. I want to order it by date and have the oldest on top. But there are some todos without a date. These todos I don\'t

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 19:43

    Yes

    SELECT * 
      FROM table 
      ORDER BY  CASE your_date 
                  WHEN '' THEN 'b' 
                  ELSE 'a' 
                END,
                date ASC 
    

提交回复
热议问题