pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brent Wood <b.wood@niwa.co.nz>
Cc: MicroUser <a.shafar@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: ORDER BY
Date: Thu, 16 Nov 2006 11:28:32 +1300
Message-ID: <455B9490.6060004@niwa.co.nz> (raw)
In-Reply-To: <AC298A15-7BCA-432A-B304-2049E9316A19@tele2.se>
References: <1163541820.580520.110310@k70g2000cwa.googlegroups.com>
	<AC298A15-7BCA-432A-B304-2049E9316A19@tele2.se>


> On 14 nov 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.
>>
>> How I can get it?

Something along these lines might work.

select * from table
where <field> !=1
order desc by <field>

union

select * from table
where <field>=1;

or if the last record is always the same, hard code the values in the 
sql instead of querying the table, which will save a few milliseconds :-)

If it is the "other" and not the "1" that you want last, change the 
first query where clause to where <field> != 'Other' & similarly change 
the second one.


Cheers,

  Brent Wood



view thread (27+ messages)  latest in thread

Message-ID: <455B9490.6060004@niwa.co.nz>
Permalink:  ../455B9490.6060004@niwa.co.nz/
Also on:    postgresql.org/message-id/455B9490.6060004@niwa.co.nz

 · 

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: b.wood@niwa.co.nz, a.shafar@gmail.com
  Subject: Re: ORDER BY
  In-Reply-To: <455B9490.6060004@niwa.co.nz>
  References: <1163541820.580520.110310@k70g2000cwa.googlegroups.com> <AC298A15-7BCA-432A-B304-2049E9316A19@tele2.se> <455B9490.6060004@niwa.co.nz>

* 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