Re: Subqueries in select clause - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Subqueries in select clause
Date
Msg-id 20010418141738.7A6ED2A3A7@mainbox.archonet.com
Whole thread Raw
In response to Subqueries in select clause  (Sara Cohen <sarina@cs.huji.ac.il>)
List pgsql-sql
Sara Cohen <sarina@cs.huji.ac.il> said:

> Hi,
> 
> I am attempting to use subqueries in the select clause of a query
> and am encountering difficulties.
> 
> The Problem:
> ------------
> 
> I would like to use a subquery that returns one column, but more than one
> tuple. The result of this subquery is then used in an aggregate function.

> Using Oracle, I could get by this problem with:
> 
>     select max(d) from ((select count(b) as d from c group by a));
> 
> However, my version of postgres doesn't support subqueries in the from
> clause.

In 7.1 at least you can do it if you alias the sub-query:

select max(d) from (select count(b) as d from c group by a) as calias;

Sorry, I don't know if 7.0.2 handles this (but you probably want to upgrade
anyway - I seem to remember some problems with 7.0.2)

HTH

- Richard Huxton


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Subqueries in select clause
Next
From: Roberto Mello
Date:
Subject: Re: maybe Offtopic : PostgreSQL & PHP ?