in reply to Going to first record on a record set in DBI

Not to denigrate the previous replies to this question, and I might be just plain wrong, but it seems to me that the question being asked hasn't been answered. I think the OP wants to loop over each row in one record set for each row in another record set.

I would do the following to accomplish this, as illustrated by the following UNTESTED code snippet:

# first, get all the results for the record set used in inner loop my $record_set_1 = $sth1->fetchall_arrayref; # loop over second record set while (my @row = $sth2->fetchrow_array) { foreach my $row_from_record_set_1 (@$record_set_1) { # blah blah } }

Of course, if the first record set is very large, you'll run into memory problems. If that's the case, then you might be able to use cursors, depending on whether your DB supports it...