with limit(20) it runs only the first 20 values of DB
The common pattern is to store the last ID processed in a variable, using variable_set(). Then you can retrieve it using variable_get() with a default of 0 before running your query, and add a condition to the query for wid being greater:

$last_id = variable_get('mymodule_last_id', 0);
...
-&gt;condition('wid', $last_id, '&gt;')

...
$last_id = value from row
variable_set('mymodule_last_id', $last_id);