title: IF Condition Perform Query, Else Perform Other Query
body: <p>It feels pretty straightforward in anything but MySQL.</p>
  
  <p>Basically I need to switch what type of index I am using along with a few other conditions based on how many results a particular term returns.</p>
  
  <p>Something to the effect of:</p>
  
  <pre><code>IF (SELECT COUNT(*) FROM table WHERE term LIKE "term") &gt; 4000
     EXECUTE QUERY A
  ELSE
     EXECUTE QUERY B
  </code></pre>
  
  <p>Is this possible in a MySQL statement?</p>
  
  <p>EDIT:</p>
  
  <p><strong>Query A:</strong></p>
  
  <pre><code>SELECT id 
  FROM table_a
  FORCE INDEX(id)
  JOIN table_b ON table_a.id = table_b.id
  WHERE term LIKE "term"
  ORDER BY date
  LIMIT 100;
  </code></pre>
  
  <p><strong>Query B:</strong></p>
  
  <pre><code>SELECT id 
  FROM table_a
  FORCE INDEX(term)
  JOIN table_b ON table_a.id = table_b.id
  WHERE term LIKE "term"
  GROUP BY term    # These lines would be included for a few conditions not mentioned above.. but are necessary
  HAVING COUNT = 1 # same...  
  ORDER BY date
  LIMIT 100;
  </code></pre>
  
  <p>The reason for the query switch is I get dramatically different result times based on the popularity of the "term".</p>