Postgresql Select Data From Subquery