my @regUsers; my $sth = $dbh->prepare("SELECT `UserName` FROM Account a, asscAccountAccountGroup aaag, asscRoleAccountGroup arag, Role r WHERE a.Id = aaag.AccountId AND aaag.AccountGroupId = arag.AccountGroupId AND arag.RoleId = r.Id AND r.Name = 'ROLE_REVIEWER';") || die "Cannot prepare the query :$!"; $sth->execute() || die "Cannot execute the query :$!"; while ( my @userRows = $sth->fetchrow_array() ) { push @regUsers, @userRows; } print join("\n",@regUsers); #### my @users = $dbh->selectall_array("SELECT `UserName` FROM Account a, asscAccountAccountGroup aaag, asscRoleAccountGroup arag, Role r WHERE a.Id = aaag.AccountId AND aaag.AccountGroupId = arag.AccountGroupId AND arag.RoleId = r.Id AND r.Name = 'ROLE_REVIEWER'"); print join("\n",@users);