Re: ORDER BY TIMESTAMP_column ASC, NULL first

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Fredrik Wendt <fredrik(at)csbnet(dot)se>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER BY TIMESTAMP_column ASC, NULL first
Date: 2004-06-03 17:31:01
Message-ID: 20040603173101.GA5022@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Feb 12, 2004 at 11:06:26 +0100,
Fredrik Wendt <fredrik(at)csbnet(dot)se> wrote:
>
> The query to use would be,
>
> SELECT ip.id FROM IPv4Address ip ORDER BY assignedAt ASC LIMIT 1;
>
> with the exception that this returns rows with NULL at the end, instead
> of at the beginning which is what I'd like.
>
> How do achieve this with one query? I'm using Postgres 7.4.

SELECT ip.id FROM IPv4Address ip ORDER BY assignedAt IS NULL,
assignedAt ASC LIMIT 1;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joseph Turner 2004-06-03 17:31:22 Selecting "sample" data from large tables.
Previous Message Enrico Weigelt 2004-06-03 17:20:02 Re: [SQL] SQL Spec Compliance Questions