Re: sub select

From: Tod McQuillin <devin(at)spamcop(dot)net>
To: Ben-Nes Michael <miki(at)canaan(dot)co(dot)il>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: sub select
Date: 2001-08-30 12:34:24
Message-ID: 20010830212701.H28610-100000@glass.pun-pun.prv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 30 Aug 2001, Ben-Nes Michael wrote:

> Can I:
>
> select *, sum_rows as ( select count(*) from table2; ) from table1;

I think you need to say:

select *, (select count(*) from table2) as sum_rows from table1;

But this won't be a very interesting query because the sum_rows column
will be the same in every row.

Where subselects get interesting is when you do a correlated subquery like
this:

select *, (select count(*) from table2 where table2.x = table1.y) as
sum_rows from table1;

--
Tod McQuillin

In response to

  • sub select at 2001-08-30 10:44:32 from Ben-Nes Michael

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2001-08-30 13:28:10 Re: getting the oid for a new tuple in a BEFORE trigger
Previous Message Andrew Snow 2001-08-30 11:20:02 RE: MySQL treads belong else where.