Add missing `distinct` to queries needing it