pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Sara Cohen <sarina@cs.huji.ac.il>
Cc: pgsql-sql@postgresql.org
Subject: Re: Subqueries in select clause
Date: Wed, 18 Apr 2001 14:17:38 -0000
Message-ID: <20010418141738.7A6ED2A3A7@mainbox.archonet.com> (raw)
In-Reply-To: <Pine.LNX.4.20_heb2.08.0104181244450.32127-100000@inferno-01.cs.huji.ac.il>

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



view thread (6+ messages)  latest in thread

Message-ID: <20010418141738.7A6ED2A3A7@mainbox.archonet.com>
Permalink:  ../20010418141738.7A6ED2A3A7@mainbox.archonet.com/
Also on:    postgresql.org/message-id/20010418141738.7A6ED2A3A7@mainbox.archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, sarina@cs.huji.ac.il
  Subject: Re: Subqueries in select clause
  In-Reply-To: <20010418141738.7A6ED2A3A7@mainbox.archonet.com>
  References: <Pine.LNX.4.20_heb2.08.0104181244450.32127-100000@inferno-01.cs.huji.ac.il> <20010418141738.7A6ED2A3A7@mainbox.archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox