in reply to Using the DBI to return the first ix/i rows
I need to return the first x rows of a 'select' statement
The most obvious way is to put a 'LIMIT x' in your SELECT.
But if for some reason you can't do that, then use something like:
my $sth = $dbh->prepare($sql); $sth->execute; $sth->bind_columns(\my ($col1, $col2 ... $coln)); my $count = 0; while ($sth->fetch) { [$col1 .. $coln will be populated with the values in that row] last if ++$count == 10; }
Tony
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Using the DBI to return the first ix/i rows
by eg (Friar) on Jan 25, 2001 at 16:36 UTC | |
by davorg (Chancellor) on Jan 25, 2001 at 16:40 UTC |