Self-join of a subquery Self-join of a subquery postgresql postgresql