Re: sub select - Mailing list pgsql-general

From Tod McQuillin
Subject Re: sub select
Date
Msg-id 20010830212701.H28610-100000@glass.pun-pun.prv
Whole thread Raw
In response to sub select  ("Ben-Nes Michael" <miki@canaan.co.il>)
List 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



pgsql-general by date:

Previous
From: "Andrew Snow"
Date:
Subject: RE: MySQL treads belong else where.
Next
From: Andrew Sullivan
Date:
Subject: --enable-syslog and Solaris 7