Re: ORDER records based on parameters in IN clause
| От | Dawid Kuroczko |
|---|---|
| Тема | Re: ORDER records based on parameters in IN clause |
| Дата | |
| Msg-id | 758d5e7f05062904445112c493@mail.gmail.com обсуждение исходный текст |
| Ответ на | ORDER records based on parameters in IN clause ("Riya Verghese" <riya.verghese@admissioncorp.com>) |
| Список | pgsql-sql |
On 6/27/05, Riya Verghese <riya.verghese@admissioncorp.com> 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
В списке pgsql-sql по дате отправления: