# Start first sql... my $dbh = DBI->connect... my $sql = " SELECT acc_num, date, user1, user2, user3, user4, user5, user6, user7, FROM users_info WHERE date='2009-04-11' "; my $sth = $dbh->prepare($sql)|| die $dbh->errstr; $sth->execute() or die "$!\n"; my $array_ref = $sth->fetchall_arrayref(); my @ar_acc_num; foreach my $vals (@$array_ref){ my ($acc_num, $date, $all_users) =@$vals; push @ar_acc_num ,$pol_num; # I will need to push $date into an array as well, but one problem at a time. } # here I have part of the data I need unshift @{ $array_ref }; # here I have all the acc numbers I need to go after on the second table: # print "@ar_acc_num"; # Start second sql... my $dbh_b = DBI->connect... my $values = join("," ,map { $dbh_sec->quote($_) } @ar_acc_num ); my $sql_b = " SELECT add, acc, date, email, phone, city, state, country, reg FROM all_info WHERE date='2009' /* # it should be the value of $date pushed previously but for now I am using static year of 2009 */ AND acc IN ($values) "; my $sth_b = $dbh_b->prepare($sql_b)|| die $dbh_b->errstr; $sth_b->execute() or die "$!\n"; my $header = [ "Acc. Num", "Date", "User 1", "User 2", "User 3", "User 4", "User 5", "User 6", "User 7", "Add", "Acc", "Email", "Phone", "City", "State", "Country", "Regular", ]; my $array_ref_b = $sth_b->fetchall_arrayref(); #***Here I need to add @{ $array_ref } to @{ $array_ref_b } to contain all the data I need to format my report, that's where my problem is, how to do that? ## @{ $array_ref_b }= @{ $array_ref }.@{ $array_ref_b }; unshift @{ $array_ref_b }, $header;