LPS-51018 Use distinct in both count and find by

Hi Shuyang,

this issue is not reproducible in Master but I think the code change still applies since the count and select queries do not match.

@ealonso wanted me to send this through you to confirm either way.