title: Get result row count for individual SELECT statements with UNION ALL in MySQL when using LIMIT
body: <p>I need to get the row count for individual SELECT statements in an UNION ALL SELECT query that uses LIMIT. The MySQL docs are pretty clear about getting the <strong>global row count</strong> for the query (place individual SELECTs in parenthesis and place an SQL_CALC_FOUND_ROWS only in the <strong>first</strong> statement, then get FOUND_ROWS() the usual way). However, I also need the result row count for the <strong>individual</strong> SELECT statements. The query, simplified:</p>
  
  <pre><code>(SELECT SQL_CALC_FOUND_ROWS `field1`,`field2` FROM `db`.`table1` WHERE `id`&gt;1000)
  UNION ALL
  (SELECT `field1`,`field2` FROM `db`.`table2` WHERE `id`&gt;1000)
  UNION ALL
  ...
  (SELECT `field1`,`field2` FROM `db`.`tableN` WHERE `id`&gt;1000)
  LIMIT 0,10
  </code></pre>
  
  <p>If SQL_CALC_FOUND_ROWS is placed in <strong>every</strong> SELECT statement an "Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'" error is issued.
  Google this a lot, read related messages here, to no avail. Might be something really simple, I just can't get my mind around it.</p>