Received: from localhost (pluto.hub.org [200.46.204.4]) by postgresql.org (Postfix) with ESMTP id 64A509F93E4 for ; Thu, 16 Nov 2006 06:10:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.4]) (amavisd-new, port 10024) with ESMTP id 78648-02 for ; Thu, 16 Nov 2006 06:10:02 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 501D79F93C9 for ; Thu, 16 Nov 2006 06:10:08 -0400 (AST) Received: from root by ciao.gmane.org with local (Exim 4.43) id 1GkeC2-000885-H6 for pgsql-general@postgresql.org; Thu, 16 Nov 2006 11:10:02 +0100 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 16 Nov 2006 11:10:02 +0100 Received: from hf1110x by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 16 Nov 2006 11:10:02 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Harald Fuchs Subject: Re: ORDER BY Date: 16 Nov 2006 11:04:15 +0100 Organization: Linux Private Site Lines: 28 Message-ID: References: <1163541820.580520.110310@k70g2000cwa.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net X-Archive: encrypt User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/1143 X-Sequence-Number: 104239 In article , Alexander Staubo 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