pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas F.O'Connell <tfo@sitening.com>
To: PgSQL - SQL <pgsql-sql@postgresql.org>
Cc: Bruno Wolff III <bruno@wolff.to>
Subject: Re: Making NULL entries appear first when ORDER BY <field> ASC
Date: Wed, 23 Feb 2005 13:54:50 -0600
Message-ID: <b27f2f6549c676ab0afe3b615e905230@sitening.com> (raw)
In-Reply-To: <200502160939.27431.andreak@officenet.no>
References: <200502160055.59288.andreak@officenet.no>
	<20050216044735.GA2343@wolff.to>
	<200502160939.27431.andreak@officenet.no>

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.




view thread (10+ messages)  latest in thread

Message-ID: <b27f2f6549c676ab0afe3b615e905230@sitening.com>
Permalink:  ../b27f2f6549c676ab0afe3b615e905230@sitening.com/
Also on:    postgresql.org/message-id/b27f2f6549c676ab0afe3b615e905230@sitening.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tfo@sitening.com, bruno@wolff.to
  Subject: Re: Making NULL entries appear first when ORDER BY <field> ASC
  In-Reply-To: <b27f2f6549c676ab0afe3b615e905230@sitening.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox