title: SELECT CASE, COUNT(*)
body: <p>I want to select the number of users that has marked some content as favorite and also return if the current user has "voted" or not. My table looks like this</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `favorites` (
  `user` int(11) NOT NULL DEFAULT '0',
  `content` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY  (`user`,`content`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 ;
  </code></pre>
  
  <p>Say I have 3 rows containing</p>
  
  <pre><code>INSERT INTO `favorites` (`user`, `content`) VALUES
  (11, 26977),
  (22, 26977),
  (33, 26977);
  </code></pre>
  
  <p>Using this</p>
  
  <pre><code>SELECT COUNT(*), CASE
          WHEN user='22'
             THEN 1
             ELSE 0
     END as has_voted
  FROM favorites WHERE content = '26977'
  </code></pre>
  
  <p>I expect to get <code>has_voted=1</code> and <code>COUNT(*)=3</code> but </p>
  
  <p>I get <code>has_voted=0</code> and <code>COUNT(*)=3</code>. Why is that? How to fix it?</p>