X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 47E41476351 for ; Sun, 13 Apr 2003 19:01:08 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 6281C476085 for ; Sun, 13 Apr 2003 19:01:07 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3DN1Y2L000432; Sun, 13 Apr 2003 19:01:34 -0400 (EDT) To: "Randolph Jones" Cc: pgsql-sql@postgresql.org Subject: Re: sort up then down In-reply-to: <3E98C24F.1070507@qwest.net> References: <3E98C24F.1070507@qwest.net> Comments: In-reply-to "Randolph Jones" message dated "Sat, 12 Apr 2003 18:50:07 -0700" Date: Sun, 13 Apr 2003 19:01:34 -0400 Message-ID: <431.1050274894@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/200 X-Sequence-Number: 12901 "Randolph Jones" writes: > I have database fields 1234567891.001; > I want to sort on first 10 digits descending; (last date first) > then ascending on the last 3 digit (page numbers) > the statement below gives the right answer, > but is this how to do it? > SELECT substr(imgname,1,10) AS name, substring(imgname,12,3) AS pg FROM > fax GROUP BY imgname, pg ORDER BY name DESC, pg ASC; The ORDER BY seems fine. I think the GROUP BY is redundant: if you're grouping by imgname, there's no effect to grouping by pg as well, no? regards, tom lane