Wednesday, March 21, 2012

Grabbing the Top Nth Records based on another table per group

Hi All,

I am trying to perform a SQl query that I have never attempted before.

I have a table with records such that would look like this

GroupField1 GroupField2 Field1 Amount

AAA BBB Field1Data 23.00

AAA BBB Feld2Data 24.00

AAA BBB Field3Data 8.00

BBB CCC Field1Data 25.00

BBB CCC Field2 Data 23.00

DDD BBH Field1Data 232.00

I have a second table that is like

GroupField1 GroupField2 NumberOfRows

AAA BBB 2

BBB CCC 1

DDD BBH 1

What I am trying to do is create a query that gets data from table 1 based on how many rows table 2 says to get.

I think the query would be something like

Select Top(select number of rows from table 2 where Table1.GroupField1 = Table2.GroupField1 and Table1.GroupField2 = Table2.GroupField2) from Table1

Anybody oput there have any expertise in this area?

Thank you,

Lynn

Wrong forum. Try posting on http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=85&SiteID=1

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights

No comments:

Post a Comment