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

sub selects

From: Jodi Kanter <jkanter(at)virginia(dot)edu>
To: Postgres Admin List <pgsql-admin(at)postgresql(dot)org>
Subject: sub selects
Date: 2002-01-23 18:07:03
Message-ID: 00d301c1a438$c30bd160$de138f80@virginia.edu (view raw or flat)
Thread:
Lists: pgsql-admin
I hope this is not too confusing..... I left my column names and table names as is but you should get the idea...

I am doing the following:

select usf_fk from am_spots where ams_pk in ((select min(ams_pk) from am_spots where am_fk>135),(select max(ams_pk) from am_spots where am_fk>135);

It works fine but I originally tried this:

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 than one field back in a sub select?

Also, I need to now embed this entire select statement into another select statement such as:

select spot_identifier from al_spots where als_pk in (SELECT STATMENT ABOVE)

Can I do this? Is there any easier way that I cannot see? Any suggestions would be appreciated.
Thanks
Jodi

Responses

pgsql-admin by date

Next:From: Tom LaneDate: 2002-01-23 19:05:21
Subject: Re: sub selects
Previous:From: Nick FankhauserDate: 2002-01-23 10:46:33
Subject: Re: Execute A String of Query

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