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  (Michael Fuhr <mike@fuhr.org>)
Re: ORDER records based on parameters in IN clause  ("Greg Sabino Mullane" <greg@turnstep.com>)
Re: ORDER records based on parameters in IN clause  (Dawid Kuroczko <qnex42@gmail.com>)
Re: ORDER records based on parameters in IN clause  (Zac <zaccheob@inwind.it>)
List pgsql-sql
<div class="Section1"><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">I have a stmt where the outer-query is limited by the results of the inner query. I would like the
outerquery to return records in the same order as the values provided in the IN clause (returned form the inner query).
</span></font><pclass="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial">The inner_query is returning id’s ordered by count(id) , i.e by most common
occurrence.</span></font><pclass="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial">In essence,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial">when I say </span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial">select * from table where id IN (2003,1342,799, 1450) </span></font><p class="MsoNormal"><font
face="Arial"size="2"><span style="font-size:10.0pt; 
font-family:Arial">I would like the records to be ordered as 2003, 1342, 799, 1450.  The outer query has no knowledge
ofthe count(id) that the inner_query is ordering by.</span></font><p class="MsoNormal"><font face="Arial"
size="2"><spanstyle="font-size:10.0pt; 
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">Currently postgres returns it in this order (1450,1342,799,2003)</span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial">Any help would be appreciated.</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial">Thanks,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">R. Verghese</span></font></div>

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 :(