SELECT M.msg_id, SND.firstname as snd_fname, SND.lastname as snd_lname, REC.firstname as rec_fname, REC.lastname as rec_lname from MSG as M -- We'll use SND as the alias for the sender join USERS as SND on M.msg_from = SND.usrid -- and REC as the alias for the recipient join USERS as REC on M.msg_to = REC.usrid #### $data->execute(); my $data_check = $data->fetchall_arrayref(); for my $row (@$data_check) { my ($msgid, $snd_fname, $snd_lname, $rec_fname, $rec_lname) = @$row; printf "% 6u %-32.32s %-32.32s\n", $msgid, join(" ", $snd_lname, $snd_fname), join(" ", $rec_lname, $rec_fname); } #### $data->execute(); my $data_check = $data->fetchall_arrayref(); while (my $row = $data->fetchrow_hashref) { printf "% 6u %-32.32s %-32.32s\n", $row->{msgid}, join(" ", $row->{snd_lname}, $row->{snd_fname}), join(" ", $row->{rec_lname}, $row->{rec_fname}); }