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

From: Ken Johanson <pg-user(at)kensystem(dot)com>
To: "Thomas F(dot)O'Connell" <tfo(at)sitening(dot)com>
Cc: PgSQL - SQL <pgsql-sql(at)postgresql(dot)org>, Bruno Wolff III <bruno(at)wolff(dot)to>
Subject: Re: Making NULL entries appear first when ORDER BY <field>
Date: 2005-02-23 20:12:39
Message-ID: 421CE3B7.1030705@kensystem.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Well, for the docs to list every possible conditional-statement for an
order by clause would just about include them all, so be all the more
confusing. Sub queries, IN, aggregate functions, aliases.. the list goes
on and on. I'd say that knowledge (that most conditionals can be used in
an order-by or group-by) should be implicit once a person has a basic
understanding of the language.

Thomas F.O'Connell wrote:

> How would one know from the reference material that it is possible to
> include IS NOT NULL in an ORDER BY clause?
>
> Similarly, other than the FAQ, I've never been able to tell from the
> SELECT documentation why ORDER BY random() works.
>
> -tfo
>
> --
> Thomas F. O'Connell
> Co-Founder, Information Architect
> Sitening, LLC
> http://www.sitening.com/
> 110 30th Avenue North, Suite 6
> Nashville, TN 37203-6320
> 615-260-0005
>
> On Feb 16, 2005, at 3:39 AM, Andreas Joseph Krogh wrote:
>
>> On Wednesday 16 February 2005 04:47, Bruno Wolff III wrote:
>>
>>>> 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.
>>
>>
>> Thanks! This si, IMO, the cleanest solution as it doesn't involve any
>> COALESCE.
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas F.O'Connell 2005-02-23 20:22:41 Re: Making NULL entries appear first when ORDER BY <field> ASC
Previous Message Thomas F.O'Connell 2005-02-23 19:54:50 Re: Making NULL entries appear first when ORDER BY <field> ASC