Reduce sql queries for groupname tests.

@cpennington @adampalay fastest part of the 4 stage fix. Use sql where in instead of individual queries for the groups.