In this
thread there are a few nodes discussing LIMIT and its implication.
This node gives a MS SQL variation.
As I have already stressed
before, the LIMIT instruction does not mean that you are fetching records from number X to Y. Relational databases don't have record numbers, unless some specific brand implementation supports such concept.
What you get with a LIMIT, is a subset of your query result, which can change depending on many factors (see an example in the above mentioned node.)
As for the example you are presenting, it does not do what you want. Your example will fetch
all the records resulting from your query, and do something for the first 20 records.
If you want only the first N records, a standard DBI method is:
my $count =0;
my $maximum = 20;
while (my $array_ref = $sth->fetchrow_arrayref()) {
last if $count++ >= $maximum;
# do something with your records
}
$sth->finish(); # will clean the memory in the database
However, a much better and strongly recommended method is using a WHERE clause in your SQL. Using WHERE you are reducing the records to select, thus speeding up the query (less records to select, less to fetch)
If you can't select what
you want using this clause, you might have some database design problems.
HTH
_ _ _ _
(_|| | |(_|><
_|
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.