pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Riya Verghese <riya.verghese@admissioncorp.com>
To: pgsql-sql@postgresql.org
Subject: ORDER records based on parameters in IN clause
Date: Mon, 27 Jun 2005 09:15:15 -0700
Message-ID: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net> (raw)

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

view thread (16+ messages)  latest in thread

Message-ID: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net>
Permalink:  ../BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net/
Also on:    postgresql.org/message-id/BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: riya.verghese@admissioncorp.com
  Subject: Re: ORDER records based on parameters in IN clause
  In-Reply-To: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net>
  References: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox