How can I build multiple queries at once with CodeIgniter QueryBuilder?
<p>I have a complex <code>SELECT</code> with several time consuming calculated fields. I only want the first 100 rows, however, I also need the total rows found. This means executing the query once with <code>LIMIT</code> and once without.</p>

<p>I would like to be able to build two <code>SELECT</code>'s simultaneously with CodeIgniter's QueryBuilder and eliminate the time consuming calculated fields on the second query.</p>

<p>I would like to know if there is a good way to do this with QB or should I just build the <code>SELECT</code> without QB.</p>

<p>UPDATE: Apparently I have confused people. I need to do something like this:</p>

<p>To get the records to display:</p>

<pre><code>SELECT id, [ several really time intensive calculated fields ]
FROM table
WHERE [some complicated criteria]
LIMIT 100;
</code></pre>

<p>To get the total records I would like to re-use the built query or build a 2nd one simultaneously but without the limit and with only the id field:</p>

<pre><code>SELECT id
FROM table
WHERE [some complicated criteria];
</code></pre>

<p>Another option; I have learned that if I put the time intensive calculated fields in a sub SELECT, Postgres will not execute it until the row is actually retrieved.</p>

<p>For now I am manually building two queries but I'd like to do it the correct QueryBuilder way.</p>