http://www.perlmonks.org?node_id=230635

peppiv has asked for the wisdom of the Perl Monks concerning the following question:

Good day y'all!

I need to limit the results of a DBI query. But here's the catch. I'm querying a SQL Server DB which does not use the LIMIT command commonly found in MySQL. Oh, if it could be that easy.

Here's the basic structure:

my $sth = $dbh->prepare("SELECT DISTINCT country, COUNT(*) FROM contac +ts WHERE country != '' GROUP BY country ORDER BY 2 DESC"); $sth->execute() or die $sth->errstr; while (my @result = $sth->fetchrow_array()) { print qq($result[0], $result[1]); } $sth->finish();

I get the return of the country and the count. But it returns all rows and I only need the first 10 - in order of descending count value.

Any help would be greatly appreciated.

I tried to put together a for statement with a count in it but that was a disaster.

TIA

peppiv