Re: order by desc - with zeros on top

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Christoph Frick <frick(at)sc-networks(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: order by desc - with zeros on top
Date: 2006-06-14 04:24:16
Message-ID: 54EC22FA-D89C-4CD3-8146-FD4668F21B2A@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


On Jun 14, 2006, at 0:29 , Christoph Frick wrote:

> IIRC there where recently a sql code snippet, that solved the
> problem of
> "ordering a list of ints descending - but keep the zero on top":

SELECT shown_production_id
FROM wherever
ORDER BY shown_production_id = 0
, shown_production_id desc;

I don't remember if TRUE sorts before FALSE, but either use = 0 or <>
0. That should work.

Michael Glaesemann
grzm seespotcode net

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message willfarnaby 2006-06-14 06:18:04 Can PostgreSQL 8.x Return Multiple "Result Sets" ?
Previous Message Tom Allison 2006-06-14 00:19:22 ruby