title: mysql multiple count in single table with different where clause
body: <p>I have three SELECT statements that do COUNTs. Thought it would be more efficient and kinder on mysql to combine these:</p>
  
  <pre><code>$query = $db-&gt;query("SELECT count(category) FROM table WHERE cid='290463' and category = 'x'"); 
           $tot_x = $db-&gt;result($query, 0);
  
  $query = $db-&gt;query("SELECT count(category) FROM table WHERE cid='290463' and category = 'y'"); 
           $tot_y = $db-&gt;result($query, 0);
  
  $query = $db-&gt;query("SELECT count(category) FROM table WHERE cid='290463' and category = 'z'"); 
           $tot_z = $db-&gt;result($query, 0);
  </code></pre>
  
  <p>into one statement:</p>
  
  <pre><code>SELECT 
      SUM(category='x' AND cid='290463') as tot_x, 
      SUM(category='y' AND cid='290463') as tot_y, 
      SUM(category='z' AND cid='290463') as tot_z 
  FROM table
  </code></pre>
  
  <p>Problem is, the new statement is slower than running the original three separately. </p>
  
  <p>Anyone able to shed light on why the new statement is slower and also recommendations to improve the SELECT to be faster?</p>