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:
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
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Limit results of a DBI query
by Fletch (Bishop) on Jan 28, 2003 at 16:51 UTC | |
by peppiv (Curate) on Jan 28, 2003 at 16:56 UTC | |
Re: Limit results of a DBI query
by mpeppler (Vicar) on Jan 28, 2003 at 16:36 UTC | |
by peppiv (Curate) on Jan 28, 2003 at 16:53 UTC | |
by mpeppler (Vicar) on Jan 28, 2003 at 21:17 UTC | |
by peppiv (Curate) on Jan 28, 2003 at 21:39 UTC | |
by mpeppler (Vicar) on Jan 28, 2003 at 21:44 UTC | |
Re: Limit results of a DBI query
by SysApe9000 (Acolyte) on Jan 28, 2003 at 17:49 UTC | |
Re: Limit results of a DBI query
by Ryszard (Priest) on Jan 29, 2003 at 07:08 UTC | |
Re: Limit results of a DBI query
by Anonymous Monk on Jun 27, 2009 at 16:15 UTC |
Back to
Seekers of Perl Wisdom