Automatic query restriction of categorical groupings