works on empty tables

Right, avoid 2 lookups and IN clauses with ids are limited to 1000.