pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Zac <zaccheob@inwind.it>
To: pgsql-sql@postgresql.org
Subject: Re: ORDER records based on parameters in IN clause
Date: Wed, 29 Jun 2005 14:09:35 +0200
Message-ID: <d9u33p$1ao3$1@news.hub.org> (raw)
In-Reply-To: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net>
References: <BBA4F47BB0CEDD4D8ADD2FE21E2823673110A4@dhost002-37.dex002.intermedia.net>

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.



view thread (16+ messages)  latest in thread

Message-ID: <d9u33p$1ao3$1@news.hub.org>
Permalink:  ../d9u33p$1ao3$1@news.hub.org/
Also on:    postgresql.org/message-id/d9u33p$1ao3$1@news.hub.org

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: zaccheob@inwind.it
  Subject: Re: ORDER records based on parameters in IN clause
  In-Reply-To: <d9u33p$1ao3$1@news.hub.org>

* 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