Read all data from a table -- calling itself again and again

Hi! I need to write selective data from one table to another one (with some joins). There are two options: 1) stored procedure in MariaDB or 2) do it with Phalcon and an action of a controller that calls itself again (say, after 100 reads/writes).

My question is, how can I realize way number 2?

This is easy: $datasets = Model::find(... 'limit' => 100); foreach ($datasets as $dataset): write-action endforeach;

Call function via URL again with lastreadid

But how do I get the next 100 one? With raw SQL I would do something like this: select * from foo where id = (select min(id) from foo where id > $lastreadid)

Sorry, but maybe I just not see the forest for the trees right now.

Thanks alot Aljoscha

What's exatly a problem ? Phalcon supports min, so wht a question ?