create view countrypartners
( country, pnames )
as select country, count(*)
from mobilePartners
group by country
select country, pnames
from countrypartners CP
where 3 >
( select count(*)
from countrypartners
where pnames > CP.pnames )
order by pnames desc
the classic form of the "top n" query is based on a column value
in this case that column value is actually an aggregate
the approach that's guaranteed to work is to create countrypartners as a table, temporary if desired
i would bet a coffee and donut on the view approach working in all databases that support views and subselects
least likely in my opinion to run, but semantically valid, would be
select country, pnames
from (
select country
, count(*) as pnames
from mobilePartners
group by country ) CP
where 3 >
( select count(*)
from (
select country
, count(*) as pnames
from mobilePartners
group by country )
where pnames > CP.pnames )
order by pnames desc
rudy
http://rudy.ca/