I would like to order SQL results in the timestamp field in descending order with the newest records. However, I have certain lines that are empty or contain zeros. How can I merge this result between future and past rows? Can this be done with CASE?
SELECT * FROM table ORDER BY when DESC
EDIT: Thanks to all the answers. Just to let everyone know, I went with MySQL IFNULL, i.e.
SELECT * FROM table ORDER BY IFNULL(when,UNIX_TIMESTAMP()) DESC
This was the easiest approach, where if it contained NULL, the select query replaced it with the current unix time. Please note that I updated my DB and replaced all 0 with NULL values.
source
share