On 6/27/05, Riya Verghese <[EMAIL PROTECTED]> wrote:
> I have a stmt where the outer-query is limited by the results of the inner
> query. I would like the outer query to return records in the same order as
> the values provided in the IN clause (returned form the inner query). 
> 
> The inner_query is returning id's ordered by count(id) , i.e by most common
> occurrence. 
> 
> In essence, 
> 
> when I say 
> 
> select * from table where id IN (2003,1342,799, 1450) 
> 
> Currently postgres returns it in this order (1450,1342,799,2003) 

Simplest, though not niciest solution would be:

SELECT * FROM table WHERE id IN (2003,1342,799,1450) ORDER BY id =
2003 DESC, id = 1342 DESC, id = 799 DESC, id = 1450 DESC;

You could write a function which will return position of interger
inside integer[] array and use it as order key. :-)

   Regards,
       Dawid

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to