Replaced query->distinct() with query->groupBy() to get the desired effect