Re: Select ... From (Select ...)? - Mailing list pgsql-novice

From Tom Lane
Subject Re: Select ... From (Select ...)?
Date
Msg-id 22319.986018311@sss.pgh.pa.us
Whole thread Raw
In response to Select ... From (Select ...)?  ("Steven O'Toole" <steven@o2l.com>)
List pgsql-novice
"Steven O'Toole" <steven@o2l.com> writes:
> Is there any way to do this kind of query in PGSQL?
> SELECT count0, count1 FROM (
> SELECT COUNT(*) AS count0
> FROM measurement
> WHERE responseTime = 0
> GROUP BY responseTime
> ), (
> SELECT COUNT(*) AS count1
> FROM measurement
> WHERE responseTime = 1
> GROUP BY responseTime
> )
> ;

PG 7.1 supports this ... but note it requires you to adhere to the
letter of the SQL spec: you must provide an alias table name for
each sub-select-in-FROM:

    SELECT ... FROM (SELECT ...) AS foo, ...

The AS word is optional, but the alias "foo" is not.

            regards, tom lane

pgsql-novice by date:

Previous
From: "ADBAAMD"
Date:
Subject: Re: Error during update from version 6.5.3 to version 7.03
Next
From: Vijay Deval
Date:
Subject: Re: DELETE FROM fails