title: Count from a table, but stop counting at a certain number
body: <p>Is there a way in MySQL to <code>COUNT(*)</code> from a table where if the number is greater than <code>x</code>, it will stop counting there? Basically, I only want to know if the number of records returned from a query is more or less than a particular number. If it's more than that number, I don't really care how many rows there are, if it's less, tell me the count.</p>
  
  <p>I've been able to fudge it like this:</p>
  
  <pre><code>-- let x be 100
  
  SELECT COUNT(*) FROM (
      SELECT `id` FROM `myTable`
      WHERE myCriteria = 1
      LIMIT 100
  ) AS temp
  </code></pre>
  
  <p>...but I was wondering if there was some handy built-in way to do this?</p>
  
  <hr>
  
  <p>Thanks for the suggestions, but I should have been more clear about the reasons behind this question. It's selecting from a couple of joined tables, each with tens of millions of records. Running <code>COUNT(*)</code> using an indexed criteria still takes about 80 seconds, running one without an index takes about 30 minutes or so. It's more about optimising the query rather than getting the correct output.</p>