Reduce sql queries for groupname tests.

STUD-1039

@adampalay @cpennington please review