X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 37099D1B17A for ; Thu, 3 Jun 2004 14:25:27 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25210-02 for ; Thu, 3 Jun 2004 17:25:27 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id B8D27D1B174 for ; Thu, 3 Jun 2004 14:25:24 -0300 (ADT) Received: (qmail 5265 invoked by uid 500); 3 Jun 2004 17:31:01 -0000 Date: Thu, 3 Jun 2004 12:31:01 -0500 From: Bruno Wolff III To: Fredrik Wendt Cc: pgsql-sql@postgresql.org Subject: Re: ORDER BY TIMESTAMP_column ASC, NULL first Message-ID: <20040603173101.GA5022@wolff.to> Mail-Followup-To: Fredrik Wendt , pgsql-sql@postgresql.org References: <20040212100626.GA21864@csbnet.se> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040212100626.GA21864@csbnet.se> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200406/23 X-Sequence-Number: 17968 On Thu, Feb 12, 2004 at 11:06:26 +0100, Fredrik Wendt 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;