Re: sub selects

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jodi Kanter <jkanter(at)virginia(dot)edu>
Cc: Postgres Admin List <pgsql-admin(at)postgresql(dot)org>
Subject: Re: sub selects
Date: 2002-01-23 19:05:21
Message-ID: 4550.1011812721@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Jodi Kanter <jkanter(at)virginia(dot)edu> writes:
> select usf_fk from am_spots where ams_pk in (select min(ams_pk), max(ams_pk=
> ) from am_spots where am_fk>135);

> I received an error saying that my subselect has too many fields. Did I use=
> the wrong syntax or is it just a postgres rule that you can't pull more th=
> an one field back in a sub select?

It's an SQL92 rule: if you are doing "foo IN (subselect)" then the
subselect must return one column to compare to foo. You are confusing
this case with "foo IN (scalar expression, scalar expression, ...)"
which is actually quite a different construct.

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jodi Kanter 2002-01-23 19:54:43 drop column?
Previous Message Jodi Kanter 2002-01-23 18:07:03 sub selects