ORDER BY a previous result

From: Álvaro G. Vicario <alvaro.NOSPAMTHANX_at_demogracia.com>
Date: Tue, 17 Feb 2009 11:31:13 +0100
Message-ID: <gne3lj$b9b$1_at_news.motzarella.org>



Is there a simple way to use a previous result in an ORDER BY clause?

I have a rather complicate query that filters, sorts and returns a series of IDs:

FOO_ID


      1
     98
     12
     33

Then, I use these IDs to fetch further information about the items they represent:

SELECT .......
FROM FOO
LEFT JOIN BAR .......
WHERE FOO_ID IN (1, 98, 12, 33) I keep the two queries separate to avoid excessive complexity. I compose the SQL code using PHP.

Right now, the second query comes unsorted from Oracle: I use PHP to sort it at a later stage in my application (my PHP skills are better than my SQL ones). Would it be possible to use the ID list to sort the second query inside Oracle?

Server runs Oracle9i Enterprise Edition Release 9.2.0.1.0

Thank you in advance.

--

Received on Tue Feb 17 2009 - 04:31:13 CST

Original text of this message