Combine two queries into one to use in loop

Combine two queries into one to use in loop

tech