Skip site navigation (1) Skip section navigation (2)

Re: two fields in subselect

From: Joseph Shraibman <jks(at)selectacast(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: two fields in subselect
Date: 2000-05-23 23:46:57
Message-ID: 392B1871.4AB5CAB@selectacast.net (view raw or flat)
Thread:
Lists: pgsql-sql
Tom Lane wrote:

> Joseph Shraibman <jks(at)selectacast(dot)net> writes:
> > I want to do this:
> > SELECT a, (select x,y,z from table2 where table1.a = table2.w), b, c
> > from table1;
> > But postgres complains:
> > ERROR:  Subselect must have only one field
>
> You haven't said what you expect to happen if table2 has zero or
> multiple matches to any one table1.a value --- but if you want a
> plain inner join you could do
>
> SELECT a, x, y, z, b, c from table1, table2 where table1.a = table2.w;
>

I can't do that. I guess I should have elaborated some more. What I
really want to do is:

SELECT a, (select x,y,z from table2 where table1.a = table2.w), b,
(select x,y,z from table2 where table1.b = table2.w),  c from table1;

And table2.w is unique.



In response to

pgsql-sql by date

Next:From: Stef telfordDate: 2000-05-24 01:36:43
Subject: Clarified Question
Previous:From: Tom LaneDate: 2000-05-23 23:32:32
Subject: Re: two fields in subselect

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group