Typescript Select Distinct Postgresql Tutorial Subquery