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 645BA329E87 for ; Sun, 19 Sep 2004 16:19:57 +0100 (BST) 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 34967-07 for ; Sun, 19 Sep 2004 15:19:54 +0000 (GMT) Received: from mail.greatgulfhomes.com (mail.greatgulfhomes.com [216.191.52.66]) by svr1.postgresql.org (Postfix) with ESMTP id E5597329E7F for ; Sun, 19 Sep 2004 16:19:50 +0100 (BST) Received: from terrynew2 ([216.191.52.74]) by mail.greatgulfhomes.com (8.12.8/8.12.8) with SMTP id i8JFToCC023849; Sun, 19 Sep 2004 11:29:50 -0400 From: To: , Subject: Re: ORDER BY and NULLs Date: Sun, 19 Sep 2004 11:17:31 -0400 Message-ID: <011d01c49e5b$c88fdb20$2766f30a@development.greatgulfhomes.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 In-Reply-To: <414D9E5D.8070708@numerixtechnology.de> X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200409/128 X-Sequence-Number: 18974 Use the coalesce() function. (coalesce returns the first non-null value in its list) Specifically ORDER BY coalesce("TO", 0), "FROM" If you have records in "TO" column whose values is LESS then 0, then you need to replace 0 with something that sorts BEFORE the first most value that your TO result can return. Terry Fielder Manager Software Development and Deployment Great Gulf Homes / Ashton Woods Homes terry@greatgulfhomes.com Fax: (416) 441-9085 > -----Original Message----- > From: pgsql-sql-owner@postgresql.org > [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of T E Schmitz > Sent: Sunday, September 19, 2004 10:58 AM > To: pgsql-sql@postgresql.org > Subject: [SQL] ORDER BY and NULLs > > > Hello, > > I am using PostgreSQL 7.4.2 and as I understand NULL values > always sort > last. > > However, I have a table from which select using two numerical > sort keys > "FROM" and "TO". "TO" might be NULL and I would like to display those > rows first (without sorting the column in descending order). > > Is there any way this can be achieved without inserting bogus values > into that column? > > -- > > > Regards/Gruß, > > Tarlika Elisabeth Schmitz > > ---------------------------(end of > broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster >