Re: ORDER BY - Mailing list pgsql-general

From Brent Wood
Subject Re: ORDER BY
Date
Msg-id 455B9490.6060004@niwa.co.nz
Whole thread Raw
In response to Re: ORDER BY  (Niklas Johansson <spot@tele2.se>)
List 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

pgsql-general by date:

Previous
From: gonzales@linuxlouis.net
Date:
Subject: Re: PostgreSQL equivalent of the Oracale 'unique' qualifier
Next
From: "whytwelve13@yahoo.com"
Date:
Subject: Re: PgSQL not recognized