ORDER records based on parameters in IN clause - Mailing list pgsql-sql

From Riya Verghese
Subject ORDER records based on parameters in IN clause
Date
Msg-id BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net
Whole thread Raw
Responses Re: ORDER records based on parameters in IN clause
Re: ORDER records based on parameters in IN clause
Re: ORDER records based on parameters in IN clause
Re: ORDER records based on parameters in IN clause
List pgsql-sql

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)

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.

 

Currently postgres returns it in this order (1450,1342,799,2003)

Any help would be appreciated.

Thanks,

R. Verghese

pgsql-sql by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: pg_attribute.attlen -1 for varchar e pbchar fields
Next
From: bumby
Date:
Subject: Help with query, stuck :(