pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Harald Fuchs <hf1110x@protecting.net>
To: pgsql-general@postgresql.org
Subject: Re: ORDER BY
Date: 16 Nov 2006 11:04:15 +0100
Message-ID: <pupsbn3dy8.fsf@srv.protecting.net> (raw)
References: <1163541820.580520.110310@k70g2000cwa.googlegroups.com>
	<DFDFB8FE-1787-4508-97C4-5FD12357936A@purefiction.net>

In article <DFDFB8FE-1787-4508-97C4-5FD12357936A@purefiction.net>,
Alexander Staubo <alex@purefiction.net> writes:

> On Nov 14, 2006, at 23:03 , MicroUser wrote:
>> I need sorted result but the way like this:
>> 
>> 0 | Anna
>> 3 | Fernando
>> 2 | Link
>> 1 | Other
>> 
>> Record '1 | Other' must by at the end of query result.

> It's not apparent from your example that you want something other
> than a purely lexicographic sort order (after all, "Other" comes
> after "Link", "Fernando" and "Anna", so "order by name" already gets
> you what you want), but I assume that's what you mean.

> If your table is sufficiently small, and the complexity of the actual
> query sufficiently low, prepending an expression sort key might
> suffice:

>    select * from foo
>    order by (case name when 'Other' then 1 else 0 end), name

Why so complicated?

SELECT whatever FROM foo ORDER BY name = 'Other', name




view thread (27+ messages)  latest in thread

Message-ID: <pupsbn3dy8.fsf@srv.protecting.net>
Permalink:  ../pupsbn3dy8.fsf@srv.protecting.net/
Also on:    postgresql.org/message-id/pupsbn3dy8.fsf@srv.protecting.net

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: hf1110x@protecting.net
  Subject: Re: ORDER BY
  In-Reply-To: <pupsbn3dy8.fsf@srv.protecting.net>
  References: <1163541820.580520.110310@k70g2000cwa.googlegroups.com> <DFDFB8FE-1787-4508-97C4-5FD12357936A@purefiction.net> <pupsbn3dy8.fsf@srv.protecting.net>

* 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