Re: Select ... From (Select ...)?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Steven O'Toole" <steven(at)o2l(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Select ... From (Select ...)?
Date: 2001-03-31 05:58:31
Message-ID: 22319.986018311@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Steven O'Toole" <steven(at)o2l(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Vijay Deval 2001-03-31 14:45:04 Re: DELETE FROM fails
Previous Message ADBAAMD 2001-03-30 23:46:57 Re: Error during update from version 6.5.3 to version 7.03