Selecting x number of rows within group

  • I am trying to select the top 20 results for each group within my query. Any suggestions?

  • Here's a working example using the Northwind DB:

    USE Northwind

    SELECT P.*

    FROM Products P

    WHERE P.ProductID IN ( SELECT TOP 2 G.ProductID

    FROM Products G

    WHERE G.CategoryID = P.CategoryID

    )

    ORDER BY P.CategoryID

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply