title: ORDER BY / CASE Combination Causing MySQL Query to Not Work
body: <p>The query below is returning a blank page.  It's caused by the ORDER BY and CASE combination, because the rest of the query works fine with something less complicated.</p>
  
  <p>Does anyone see any glaring errors in this part:</p>
  
  <pre><code>ORDER BY CASE 
             WHEN s.datesubmitted &gt; DATE_SUB(NOW(), INTERVAL 1 HOUR) THEN s.points 
             WHEN s.datesubmitted &lt; DATE_SUB(NOW(), INTERVAL 1 HOUR) THEN most_recent 
           END, DESC 
  </code></pre>
  
  <h3>Code:</h3>
  
  <pre><code>$sqlStr = "SELECT s.loginid, s.title, s.url, s.displayurl, s.points, s.datesubmitted, l.username,
                    s.submissionid, s.subcheck, s.topten, COUNT(c.commentid) countComments, 
                    GREATEST(s.datesubmitted, COALESCE(MAX(c.datecommented), s.datesubmitted)) AS most_recent
               FROM submission s
               JOIN login l ON s.loginid = l.loginid
          LEFT JOIN comment c ON s.submissionid = c.submissionid
           GROUP BY s.submissionid
           ORDER BY CASE 
                      WHEN s.datesubmitted &gt; DATE_SUB(NOW(), INTERVAL 1 HOUR) THEN s.points 
                      WHEN s.datesubmitted &lt; DATE_SUB(NOW(), INTERVAL 1 HOUR) THEN most_recent 
                    END, DESC                  
              LIMIT $offset, $rowsperpage";
  </code></pre>