View Full Version : Top 10 within a few groups


Alc
06-27-2007, 05:48 AM
I have a query that returns the following values:

Group_Name
Group_Priority
Person_Name
Amt_From
Amt_To
Branch
ID_Number

How can I select from this to get the top 10 'Amt_From' values within each Group_Name, in one query?

I can get the top 10 overall, and I can find the top 10 by specifiying a Group_Name value, but I'm hoping to find all in one query.

Any ideas gratefully received.

MStef
06-27-2007, 05:58 AM
I'm afraid that you need 2 queryes.

Alc
06-27-2007, 06:00 AM
Thanks for the response.

I can live with using two - could you point me in the right direction? I'm thinking a union of some sort, but not getting much further.

Alc
06-27-2007, 06:15 AM
Got it!

I had to Union query the results of six separate queries, but it worked.

In case it's of any use to anyone else, the result looks like this:


(SELECT
Top 10 Amt_From,
Amt_To,
Group_Name,
Group_Priority,
Person_Name,
Branch,
ID_Number
FROM
[Qry_Conf_Lead_Board]
WHERE
Group_Name = 'ATLANTIC')
UNION
(SELECT
Top 10 Amt_From,
Amt_To,
Group_Name,
Group_Priority,
Person_Name,
Branch,
ID_Number
FROM
[Qry_Conf_Lead_Board]
WHERE
Group_Name = 'QUEBEC')
UNION
etc.
etc.


Thanks for the pointer, MStef. Made all the difference. :)