Re: ORDER BY

From: Brent Wood <b(dot)wood(at)niwa(dot)co(dot)nz>
To:
Cc: MicroUser <a(dot)shafar(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: ORDER BY
Date: 2006-11-15 22:28:32
Message-ID: 455B9490.6060004@niwa.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message whytwelve13@yahoo.com 2006-11-15 22:37:12 Re: PgSQL not recognized
Previous Message Ron Johnson 2006-11-15 22:13:10 Re: Using SAN Splits to instantly copy a DB