Skip site navigation (1) Skip section navigation (2)

subquery question

From: Tom Raney <twraney(at)comcast(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: subquery question
Date: 2009-02-01 00:13:15
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
I've dug around on the Postgres lists for a bit and I haven't found a 
good explanation of why this query is not allowed. 

SELECT Temp.team_id, Temp.count_agents
FROM (SELECT TR.team_id, COUNT(TR.agent_id) AS count_agents
      FROM teamrel TR
      GROUP BY TR.team_id ) AS Temp
WHERE Temp.count_agents = (SELECT MIN (Temp.count_agents) FROM Temp)

I know that column aliases are not accessible in the WHERE clause, but why can't we access outer table aliases in a subquery FROM clause?  Is the table alias rewritten into the select clause?



pgsql-novice by date

Next:From: Richard BroersmaDate: 2009-02-01 03:58:56
Subject: Re: subquery question
Previous:From: Jasen BettsDate: 2009-01-31 09:53:23
Subject: Re: Select START and MAXVALUE from Sequence

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group