Re: Making NULL entries appear first when ORDER BY - Mailing list pgsql-sql

From Ragnar Hafstað
Subject Re: Making NULL entries appear first when ORDER BY
Date
Msg-id 1108521073.28180.5.camel@localhost.localdomain
Whole thread Raw
In response to Making NULL entries appear first when ORDER BY ASC  (Andreas Joseph Krogh <andreak@officenet.no>)
List pgsql-sql
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




pgsql-sql by date:

Previous
From: Rosser Schwarz
Date:
Subject: Re: Making NULL entries appear first when ORDER BY ASC
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: Making NULL entries appear first when ORDER BY ASC