How to retrieve the top N rows for each group
-- Solution   for   SQL   Server   2000   and   later       SELECT   ProductID ,           CategoryID ,           UnitPrice    FROM     @ Products   p1    WHERE    ProductID   IN  ( SELECT   TOP   3   ProductID                          FROM     @ Products   p2                          WHERE    p1 . CategoryID  =  p2 . CategoryID                          ORDER    BY   UnitPrice ...