Query in a loop, a bad idea in general. Fetch all rows at once since you are not expected millions of rows?