Re: Stored Procedure Assistance

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Bradley J(dot) Bartram" <bbartram(at)dyrectmedia(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Stored Procedure Assistance
Date: 2003-07-08 17:27:12
Message-ID: 200307081827.12833.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday 08 Jul 2003 5:55 pm, Bradley J. Bartram wrote:
> The first query is simple:
>
> SELECT a FROM table_a WHERE column_a = b
>
> This will return a single row. The next query takes that derived value and
> does a simliar select that returns multiple rows.
>
> SELECT c FROM table_b WHERE column_b = a
>
> The next query has some logic in php that constructs it. Basically if c >
> 0 than the results of query 2 are setup as ORs in the WHERE clause.
>
> SELECT d FROM table_c WHERE column_c = c1 OR column_c = c2, etc.
>
> The first two queries are not a problem, but how can I take the array of
> results from query 2 and put them into query 3?

Well, we can combine (1) and (2):

SELECT c FROM table_b, table_a
WHERE table_b.column_b = table_a.a
AND table_a.column_a = b;

The third needs to be something like:

SELECT d FROM table_c WHERE column_c IN (...the combined select above...)

So long as you don't have too many results this should work fine - no need for
a stored procedure at all.

If I've understood your problem, that should work.
--
Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dragan Matic 2003-07-08 17:38:25 Is Postgres broken in Red Hat 9?
Previous Message Michael Pohl 2003-07-08 17:25:30 Re: Stored Procedure Assistance