title: Mysql ORDER BY using date data row
body: <p>I have a query something like this:</p>
  
  <pre><code>SELECT 
   title, desc, date 
  FROM 
   tablename 
  ORDER BY 
   date ASC, title ASC;
  </code></pre>
  
  <p>Works fine when the data actually has a date. Issue is, date submission is optional, so I sometimes get 0000-00-00 as a date, which has the unfortunate effect of placing all nondated rows on top.</p>
  
  <p>So, I then tried this:</p>
  
  <pre><code>SELECT 
   title, desc, date 
  FROM 
   tablename 
  ORDER BY 
   date DESC, title ASC;
  </code></pre>
  
  <p>Which sort of works, but not really -- all items with dates (non 0000-00-00) get listed in descending order, followed by all items with 0000-00-00.</p>
  
  <p>What I want to do is order by date ASC, title ASC, but only if the date != 0000-00-00, but if date is = 0000-00-00, then just ORDER BY title ASC on those (I think I explained that correctly).</p>
  
  <p>The only ways I can think to do this are non-SQL based (either 2 queries, or, each query just populates an in-memory array, and then I sort using PHP).</p>
  
  <p>Is there a SQL query that can do this?</p>