select top 10 o.objid, COUNT(*) --o.objid) from GR4Plus5..PhotoObjAll1 o --inner loop join GR5xDR7 x on x.objid1 = o.objid -- join BestDR7..PhotoPrimary s on s.objID = x.objid2 inner join GR4Plus5..photoExtractprimary e on e.photoExtractID = o.photoExtractID where e.mpstype = 'AIS' and e.radius = 30 group by o.objid order by 1