-- Q1: no batch processing select m.MediaId, COUNT(p.IP) PurchaseCount from dbo.Media m left outer join dbo.Purchase p on p.MediaId=m.MediaId group by m.MediaId order by COUNT(p.IP) desc -- Q2: batch processing enabled (different result than Q1) select m.MediaId, COUNT(p.IP) PurchaseCount from dbo.Media m join dbo.Purchase p on p.MediaId=m.MediaId group by m.MediaId order by COUNT(p.IP) desc; -- Q3: Q1 query rewrite, same result, but with batch processing. -- This relies on the fact that m.MediaId is constrained to be not null. with T (MediaId, PurchaseCount) as ( select m.MediaId, COUNT(p.IP) PurchaseCount from dbo.Media m join dbo.Purchase p on p.MediaId=m.MediaId group by m.MediaId ) select m.MediaId, ISNULL(T.PurchaseCount,0) from Media m left outer join T on m.MediaId=T.MediaId order by ISNULL(T.PurchaseCount,0) desc;