my $dbh = DBI->connect('DBI:mysql:DB', 'user_n', $pass) or die "Failed connecting to DB " . DBI->errstr; my ($groups, $results); my $sth = $dbh->prepare_cached(<execute or die "executing: ", $dbh->errstr;; $sth->bind_columns(undef, \$groups); #bind the results--only contains unique group results. my $sth_x = $dbh->prepare_cached(<$groups
"; while ($sth->fetch) { $found++; $sth_x->execute($groups) or die "executing: ", $dbh->errstr; #find results using the results from the first query $sth_x->bind_columns(undef, \$results); while($sth_x->fetch) { $found_x++; print "$results
"; } unless($found_x) { print "empty for this group"; } print "
"; my $found_x = 0; #reset 2nd search found for next group result query. } unless ($found) { print "no groups matched"; }