Using iterator eased the solution. No set query needed.