title: How can I efficiently identify the most popular strings in a large table?
body: <p>Assuming a table of 50 million last names (for example), how would one efficiently identify the top 10,000?</p>
  
  <p>Is there a more efficient query than this?</p>
  
  <pre><code>SELECT count(last_name) as cnt, last_name
  FROM last_name_table
  GROUP BY last_name
  ORDER BY cnt DESC
  LIMIT 10000;
  </code></pre>
  
  <p>Assuming:</p>
  
  <pre><code>CREATE TABLE last_name_table (
      `last_name` VARCHAR(255), 
       KEY `last_name` (`last_name`)
  );
  </code></pre>
  
  <p>I can get the top 1000 in 20 minutes.  But the top 10000 is taking all day (literally).  Any suggestions?</p>