On Tue, Jul 08, 2003 at 12:55:00PM -0400, Bradley J. Bartram wrote:
> 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?
Huh... why don't you do a
SELECT d FROM table_c WHERE column_c IN (SELECT c FROM table_b WHERE column_b = a)
(or convert to EXISTS for performance)
Another approach could be to build a string, say
string = ''SELECT d FROM table_c WHERE '';
FOR blah IN SELECT-values-for-c LOOP
string = string || ''OR column_c = '' || blah
END LOOP;
EXECUTE string;
(adjust as needed, exclude the OR in the first iteration, etc)
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Los romanticos son seres que mueren de deseos de vida"