Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group