ORDER BY timestamp with NULLs between future and past <p>I would like to order SQL results by a timestamp field in descending order with newest entries first. However, I have certain rows that are blank or contain zeros. How can I sandwich these result in between future and past rows? Can this be done with CASEs?</p> <pre><code>SELECT * FROM table ORDER BY when DESC </code></pre> <p>EDIT: Thanks to all the responses. Just so everyone knows, I went with MySQL's IFNULL, i.e.</p> <pre><code>SELECT * FROM table ORDER BY IFNULL(when,UNIX_TIMESTAMP()) DESC </code></pre> <p>This was the simplest approach, where if when contained NULL the select query replaced it with the current unix time. Note that I updated my DB and replaced all 0s with NULL values.</p>