Wise Monks,

I have multiple hashrefs of HoH’s, which are populated with data from multiple tables within a database. Having understood how to associate a Primary Key to a Foreign Key by doing the following:
$sql1 = “select * from table1”; $sql2 = “select * from table2”; my $table1= $dbh->selectall_hashref($sql1, "primary_key"); my $table2= $dbh->selectall_hashref($sql2, "primary_key"); foreach (keys(%$table1)) { $table1_foreign_key = $table2->{$table1->{$_}{foreign_key}}{primary_key}; }

My Problem is this: There exists a $table3 that has a primary_key that is not associated with a foreign_key in $table1. The only way to associate records is through a foreign_key_table3 subkey that exists in both $table1 and $table3 hashrefs. How can I extrapolate records from $table1 and $table3 hashref’s that share the same subkey value for the foreign_key_table3 subkey?

Thanks, 3dbc.

UPDATE:

foreach $tbl1_primary (keys(%$table1)) { foreach (keys(%$table3)) { while ( $table3->{$_}{$table1->{$tbl1_primary}{foreign_key}} == $table3->{$_}{foreign_key} ) { $table1_foreign_key_table3 = $table3->{$_}{$table1->{$tbl1_primary}{foreign_key}}; } } }
update2
$sql_obfuscate = qq { SELECT * FROM clinvest.dbf a, clinvpmt.dbf b, clinvchg.dbf c, ernames.dbf d, ercontct.dbf e WHERE a.CID = b.INVESTID and a.CID = c.INVESTID and a.NAMEID = d.NAMEID and a.NAMEID = e.NAMEID };

In reply to associating subkeys of separate HoH's by 3dbc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.