in reply to Re: dbi question
in thread dbi question

Depending on what percentage of the rows in the table in the second query that you expect to hit, you could cache the results of the inner query, something like this:
my $inner_query = $dbh->prepare([inner query]); # $inner_query will have a bind param my $outer_query = $dbh->prepare([outer_query]); my %inner_cache; while ( my $data_ref = $outer_query->fetchrow_hashref() ) { if ( ! exists $inner_cache{$data_ref->{some_field}} ) { $inner_query->execute($data_ref->{some_field}}; $inner_cache{$data_ref->{some_field}} = $inner_query->fetchrow_h +ashref(); $inner_query->finish(); } my $inner_result = $inner_cache{$data_ref->{some_field}}; # do whatever } ...