pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreak@officenet.no>
To: pgsql-sql@postgresql.org
Subject: Making NULL entries appear first when ORDER BY <field> ASC
Date: Wed, 16 Feb 2005 00:55:54 +0000
Message-ID: <200502160055.59288.andreak@officenet.no> (raw)

Hi, I have the following table, with the query below to list entries from it 
where start_date IS NOT NULL:

CREATE TABLE onp_crm_activity_log(
id serial PRIMARY KEY,
start_date timestamp,
start_time timestamp,
end_time timestamp,
title varchar NOT NULL
);

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?


-- 
Andreas Joseph Krogh <andreak@officenet.no>
Senior Software Developer / Manager
gpg public_key: http://dev.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Hoffsveien 17           | know how to do a thing and to watch         |
PO. Box 425 Skøyen      | somebody else doing it wrong, without       |
0213 Oslo               | comment.                                    |
NORWAY                  |                                             |
Phone : +47 22 13 01 00 |                                             |
Direct: +47 22 13 10 03 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

view thread (10+ messages)  latest in thread

Message-ID: <200502160055.59288.andreak@officenet.no>
Permalink:  ../200502160055.59288.andreak@officenet.no/
Also on:    postgresql.org/message-id/200502160055.59288.andreak@officenet.no

 · 

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: andreak@officenet.no
  Subject: Re: Making NULL entries appear first when ORDER BY <field> ASC
  In-Reply-To: <200502160055.59288.andreak@officenet.no>

* 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