Re: JOIN on set of rows?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Fein <pfein(at)pobox(dot)com>
Cc: Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: JOIN on set of rows?
Date: 2005-05-11 16:07:43
Message-ID: 4719.1115827663@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Fein <pfein(at)pobox(dot)com> writes:
> Sorry, I kinda wrote that wrong. ;) What I really want is:

> SELECT rows of known, app-generated (app_name, app_id)
> INTERSECT
> SELECT t1.symbol AS app_name, t2.outside_key AS app_id
> FROM t2 LEFT JOIN t1 ON t1.t2_id=t2.id

> There are around a max of 50 rows in the first select and
> perhaps up to 1 million in the second.

You could do it like

(
SELECT appname1, appid1
UNION ALL
SELECT appname2, appid2
UNION ALL
...
SELECT appnameN, appidN
)
INTERSECT
SELECT ...

The UNION ALL bit is a tad grotty, but it will do until someone gets
around to implementing the full SQL VALUES construct.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mark Borins 2005-05-11 16:12:34 Re: Disabling Triggers
Previous Message Bruce Momjian 2005-05-11 16:07:03 Re: Note: Compiling on Windows with free Microsoft compilers