Re: Making NULL entries appear first when ORDER BY <field> ASC

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Making NULL entries appear first when ORDER BY <field> ASC
Date: 2005-02-16 04:47:35
Message-ID: 20050216044735.GA2343@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>
> 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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Joseph Krogh 2005-02-16 09:39:06 Re: Making NULL entries appear first when ORDER BY <field> ASC
Previous Message Greg Sabino Mullane 2005-02-16 04:08:30 Re: Making NULL entries appear first when ORDER BY <field> ASC