Suggest you post a copy of your data base with just enough records (100 or so) to show us typical data.
Also recommend you compact and repair the database and post it as a zip file.
The Title of your post is Top 5, but in your sample SQL you don't deal with 5???
I set up 100 sample records and used the following based on your posted SQL
Code:
SELECT DUMMY.tCountry
,DUMMY.nSales
,DUMMY.tCompany
FROM CompInfo AS DUMMY
WHERE DUMMY.tCompany IN (
SELECT TOP 5 tCompany
FROM Compinfo AS Dupe
WHERE Dupe.tCountry = DUMMY.tCountry
ORDER BY Dupe.nSales DESC
,Dupe.tCountry DESC
)
ORDER BY DUMMY.tCountry
,DUMMY.nSales DESC
,DUMMY.tCompany
Sample output:
Code:
tCountry |
nSales |
tCompany |
Bahamas |
73383 |
Massa Quisque Foundation |
Bahamas |
47538 |
Nulla Associates |
Bahamas |
44320 |
Commodo Tincidunt Nibh Corporation |
Bahamas |
42419 |
Nunc Limited |
Bahamas |
31655 |
Vel Sapien LLC |
Canada |
89260 |
Convallis Inc. |
Canada |
85855 |
Sit Amet PC |
Canada |
81097 |
Eget Metus Eu Limited |
Canada |
77678 |
Eu Ultrices Sit LLC |
Canada |
73302 |
Magna Praesent Company |
Denmark |
70122 |
Vestibulum Massa Rutrum PC |
Denmark |
43782 |
Sapien Cursus Ltd |
Denmark |
43079 |
Vehicula Pellentesque Foundation |
Denmark |
20037 |
Ultrices Iaculis Odio Foundation |
Denmark |
13667 |
Malesuada Malesuada LLC |