update algorithm for select with multiple tables