title: GROUP BY and ORDER BY too slow. How to make faster?
body: <p>I've trying to create some stats for my table but it has over 3 million rows so it is really slow.</p>
  
  <p>I'm trying to find the most popular value for column <code>name</code> and also showing how many times it pops up.</p>
  
  <p>I'm using this at the momment but it  doesn't work cause its too slow and I just get errors.</p>
  
  <pre><code>    $total = mysql_query("SELECT `name`, COUNT(*) as b FROM `people` GROUP BY `name` ORDER BY `b` DESC LIMIT 0,5;")or die(mysql_error());
  </code></pre>
  
  <p>As you may see I'm trying to get all the names and how many times that name has been used but only show the top 5 to hopefully speed it up.</p>
  
  <p>I would like to be able to then do get the values like</p>
  
  <pre><code>   while($row = mysql_fetch_array($result)){
          echo $row['name'].': '.$row['b']."\r\n";
     }
  </code></pre>
  
  <p>And it will show things like this;</p>
  
  <pre><code>  Bob: 215
    Steve: 120
    Sophie: 118
    RandomGuy: 50
    RandomGirl: 50
  </code></pre>
  
  <p>I don't care much about ordering the names afterwards like RandomGirl and RandomGuy been the wrong way round.</p>
  
  <p>I think I've have provided enough information. :) I would like the names to be case-insensitive if possible though. Bob should be the same as BoB, bOb, BOB and so on.</p>
  
  <p>Thank-you for your time
  Paul</p>