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 204848BA3B0 for ; Wed, 16 Feb 2005 02:31:18 +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 63525-07 for ; Wed, 16 Feb 2005 02:31:06 +0000 (GMT) Received: from quasar.skima.is (quasar.skima.is [212.30.200.205]) by svr1.postgresql.org (Postfix) with ESMTP id D518C8BA3B7 for ; Wed, 16 Feb 2005 02:30:59 +0000 (GMT) Received: from gnari ([157.157.192.100] [157.157.192.100]) by quasar.skima.is with ESMTP; Wed, 16 Feb 2005 02:30:53 Z Subject: Re: Making NULL entries appear first when ORDER BY From: Ragnar =?ISO-8859-1?Q?Hafsta=F0?= To: Andreas Joseph Krogh Cc: pgsql-sql@postgresql.org In-Reply-To: <200502160055.59288.andreak@officenet.no> References: <200502160055.59288.andreak@officenet.no> Content-Type: text/plain Date: Wed, 16 Feb 2005 02:31:13 +0000 Message-Id: <1108521073.28180.5.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200502/157 X-Sequence-Number: 20268 On Wed, 2005-02-16 at 00:55 +0000, Andreas Joseph Krogh wrote: > 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 ASC; > > start_date | start_time | end_time | title > ---------------------+---------------------+---------------------+----------- > 2005-02-03 00:00:00 | 2005-02-03 08:00:00 | | Something > 2005-02-03 00:00:00 | 2005-02-03 09:00:00 | 2005-02-03 12:00:00 | Something > 2005-02-03 00:00:00 | | | Something > > > 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? how about ORDER BY start_date , COALESCE(start_time,'0001-01-01 00:00:00'::timestamp) ? gnari