pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedtwo fields in subselect
3+ messages / 2 participants
[nested] [flat]
* two fields in subselect
@ 2000-05-23 22:53 Joseph Shraibman <jks@selectacast.net>
2000-05-23 23:32 ` Re: two fields in subselect Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Joseph Shraibman @ 2000-05-23 22:53 UTC (permalink / raw)
To: pgsql-sql
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
How can I get around this?
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: two fields in subselect
2000-05-23 22:53 two fields in subselect Joseph Shraibman <jks@selectacast.net>
@ 2000-05-23 23:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2000-05-23 23:46 ` Re: two fields in subselect Joseph Shraibman <jks@selectacast.net>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2000-05-23 23:32 UTC (permalink / raw)
To: Joseph Shraibman <jks@selectacast.net>; +Cc: pgsql-sql
Joseph Shraibman <jks@selectacast.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;
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: two fields in subselect
2000-05-23 22:53 two fields in subselect Joseph Shraibman <jks@selectacast.net>
2000-05-23 23:32 ` Re: two fields in subselect Tom Lane <tgl@sss.pgh.pa.us>
@ 2000-05-23 23:46 ` Joseph Shraibman <jks@selectacast.net>
0 siblings, 0 replies; 3+ messages in thread
From: Joseph Shraibman @ 2000-05-23 23:46 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Tom Lane wrote:
> Joseph Shraibman <jks@selectacast.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.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-05-23 23:46 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-05-23 22:53 two fields in subselect Joseph Shraibman <jks@selectacast.net>
2000-05-23 23:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2000-05-23 23:46 ` Joseph Shraibman <jks@selectacast.net>
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