Drupal db_select PDO Statement: ORDER BY CASE <p>Hi I have written a MySQL statement that has a conditional order by clause which you can see in the example below.</p> <p><strong>MySQL Example:</strong></p> <pre><code>SELECT title, description FROM books WHERE title LIKE "%keyword%" OR description LIKE "%keyword%" ORDER BY CASE WHEN title LIKE "%keyword%" THEN 1 ELSE 2 END </code></pre> <p>I am now trying to recreate this statement in Drupal using its PDO style db_select() function. But I have got stuck when writing the ORDER BY clause.</p> <p><strong>Drupal Example:</strong></p> <pre><code> $node_select = db_select('node', 'n'); $node_select-&gt;fields('n', array('title', 'description')); $node_select-&gt;condition( db_or()-&gt;condition('n.title', '%'.$keyword.'%', 'LIKE') -&gt;condition('n.description', '%'.$keyword.'%', 'LIKE') ); $node_select-&gt;order(); </code></pre> <p>Can anyone point me in the right direction on how you would write the ORDER BY section? </p>