Re: ORDER records based on parameters in IN clause

From: Zac <zaccheob(at)inwind(dot)it>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER records based on parameters in IN clause
Date: 2005-06-29 12:09:35
Message-ID: d9u33p$1ao3$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Riya Verghese wrote:
> select * from table where id IN (2003,1342,799, 1450)
>
> I would like the records to be ordered as 2003, 1342, 799, 1450. The
> outer query has no knowledge of the count(id) that the inner_query is
> ordering by.
I think this is the real problem: outer query must know count(id) to
order by count(id). You can use it in the outer with something like this:

SELECT
table.*
FROM
table
JOIN (SELECT id, count(id) AS count FROM... your subquery) AS x
ORDER BY
x.count

Bye.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Zac 2005-06-29 12:12:07 Re: ORDER records based on parameters in IN clause
Previous Message Michael Fuhr 2005-06-29 11:57:23 Re: ORDER records based on parameters in IN clause