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