Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLa0v-0002VC-DD for pgsql-sql@arkaria.postgresql.org; Mon, 16 Sep 2013 14:42:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VLa0u-0005dQ-Su for pgsql-sql@arkaria.postgresql.org; Mon, 16 Sep 2013 14:42:56 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLa0u-0005cI-06 for pgsql-sql@postgresql.org; Mon, 16 Sep 2013 14:42:56 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLa0n-0000G5-Nk for pgsql-sql@postgresql.org; Mon, 16 Sep 2013 14:42:55 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VLa0n-0000ei-Eo for pgsql-sql@postgresql.org; Mon, 16 Sep 2013 07:42:49 -0700 Date: Mon, 16 Sep 2013 07:42:49 -0700 (PDT) From: David Johnston To: pgsql-sql@postgresql.org Message-ID: <1379342569452-5771096.post@n5.nabble.com> In-Reply-To: References: Subject: Re: removing duplicates and using sort MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 4.5 (++++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Note that you could always do something like: WITH original_query AS ( SELECT DISTINCT ... ) SELECT * FROM original_query ORDER BY lastname, firstname; OR SELECT * FROM ( SELECT DISTINCT .... ) sub_query ORDER BY lastname, firstname I am thinking you cannot alter the existing ORDER BY otherwise your use of "DISTINCT ON" begins to mal-function. I dislike DISTINCT ON generally but do not wish to ponder how you can avoid it, so I'd suggest just turning your query into a sub-query like I show above. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/removing-duplicates-and-using-sort-tp5770931p5771096.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql