Typescript Select Distinct Postgresql Foreign