in reply to Merging Results from 3 different queries
If you formatted your post, you'd probably get more responses.
Assuming that each of your queries produces a hashref containing the same keys, then printing the values as you've asked might look something like this:
my $hash_ref1 = $dbh->selectall_hashref( $sql1, $key_field1, {}, @valu +es1 ); my $hash_ref2 = $dbh->selectall_hashref( $sql2, $key_field2, {}, @valu +es2 ); my $hash_ref3 = $dbh->selectall_hashref( $sql3, $key_field3, {}, @valu +es3 ); ## for each id for my $id ( keys %{ $hashref1 } ) { ## extract an array of results for that key from each hash my @results1 = @{ $hashref1->{ $id } }; my @results2 = @{ $hashref2->{ $id } }; my @results3 = @{ $hashref3->{ $id } }; ## join them together with spaces ## and print them along with the key printf "%14s : %s \t%s\t%s\n", $id, join( ' ', @results1 ), join( ' ', @results2 ), join( ' ', @results3 ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Merging Results from 3 different queries
by MegaVoice (Novice) on Jul 24, 2007 at 17:37 UTC | |
by BrowserUk (Patriarch) on Jul 24, 2007 at 17:46 UTC | |
by MegaVoice (Novice) on Jul 24, 2007 at 18:02 UTC | |
by BrowserUk (Patriarch) on Jul 24, 2007 at 18:40 UTC |