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 6B7B38BA3E0 for ; Wed, 16 Feb 2005 04:33:35 +0000 (GMT) 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 18982-09 for ; Wed, 16 Feb 2005 04:33:19 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 829C68B9B27 for ; Wed, 16 Feb 2005 04:32:41 +0000 (GMT) Received: (qmail 2480 invoked by uid 500); 16 Feb 2005 04:47:35 -0000 Date: Tue, 15 Feb 2005 22:47:35 -0600 From: Bruno Wolff III To: Andreas Joseph Krogh Cc: pgsql-sql@postgresql.org Subject: Re: Making NULL entries appear first when ORDER BY ASC Message-ID: <20050216044735.GA2343@wolff.to> Mail-Followup-To: Andreas Joseph Krogh , pgsql-sql@postgresql.org References: <200502160055.59288.andreak@officenet.no> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200502160055.59288.andreak@officenet.no> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/159 X-Sequence-Number: 20270 > > Now, as you see, touples with NULL in the "start_time"-field appear "after" > the others. I would like to make all entries where start_time IS NULL apear > *before* all the others. Any idea how to achieve this? SELECT start_date, start_time, end_time, title FROM onp_crm_activity_log WHERE start_date IS NOT NULL ORDER BY start_date ASC, start_time IS NOT NULL ASC, start_time ASC; This assumes you want the NULL start times first within a particular date. Otherwise change the order in the ORDER BY clause.