X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6B973529C2 for ; Wed, 29 Jun 2005 09:13:11 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42652-06 for ; Wed, 29 Jun 2005 12:13:06 +0000 (GMT) Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 744B952971 for ; Wed, 29 Jun 2005 09:13:06 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 83E6530B41; Wed, 29 Jun 2005 14:15:36 +0200 (MET DST) From: Zac X-Newsgroups: pgsql.sql Subject: Re: ORDER records based on parameters in IN clause Date: Wed, 29 Jun 2005 14:12:07 +0200 Organization: Hub.Org Networking Services Lines: 18 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en In-Reply-To: To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.141 tagged_above=0 required=5 tests=AWL, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200506/352 X-Sequence-Number: 21953 > SELECT > table.* > FROM > table > JOIN (SELECT id, count(id) AS count FROM... your subquery) AS x > ORDER BY > x.count > > Bye. Sorry: I forgot join condition: SELECT table.* FROM table JOIN (SELECT id, count(id) AS count FROM... your subquery) AS x ON (table.id = x.id) ORDER BY x.count