Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 062589FA4E5 for ; Wed, 14 Mar 2007 13:11:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 97502-04 for ; Wed, 14 Mar 2007 13:11:44 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from 137086.vserver.de (vs137086.vserver.de [62.75.137.86]) by postgresql.org (Postfix) with ESMTP id 264879FB5FD for ; Wed, 14 Mar 2007 13:11:43 -0300 (ADT) Received: from a-kretschmer.de (p54b3bb34.dip0.t-ipconnect.de [84.179.187.52]) (authenticated bits=0) by 137086.vserver.de (8.12.8/8.12.8) with ESMTP id l2EGBbI2023567 for ; Wed, 14 Mar 2007 17:11:39 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.61) (envelope-from ) id 1HRW5b-0001uz-6W for pgsql-sql@postgresql.org; Wed, 14 Mar 2007 17:12:35 +0100 Date: Wed, 14 Mar 2007 17:12:35 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: ordering by multiple columns Message-ID: <20070314161235.GB3930@KanotixBox> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: mutt-ng 1.5.9i (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.431 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200703/200 X-Sequence-Number: 27838 Pablo Barrón schrieb: > > Hi! > > I'm trying to order a list in which the first parameter to order is a specific > field, and the second should vary depending on a specific condition. More > explicit, I would like to do something like: > > - ORDER BY a.column1, [b.column2 if c.value != 19 || c.column2 if c.value==19] > > That is to say, use a column if a value on each row isn't 19, OR use a > different column if it isn't. How could I solve this? I've got to have a global You can do something like this: order by a.column1, case when c.value != 19 then b.column2 else c.column2 end; *untested*, but the way is to use a case when then ... else ... end; - construct. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknow) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°