 <p>Instead of pulling back a 1000 rows of data, why not make 2 sql calls? One to query for the first record:</p> <pre><code>SELECT id FROM (SELECT id FROM `table` LIMIT 0, 1000) tmp ORDER BY id LIMIT 1 </code></pre> <p>And one for the second:</p> <pre><code>SELECT id FROM (SELECT id FROM `table` LIMIT 0, 1000) tmp ORDER BY id DESC LIMIT 1 </code></pre>