Updated query for distinct if Fields are passed

The logic previously in place prevented fields from being passed and thus failing on custom pagination and fields query.