Re: ORDER records based on parameters in IN clause

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Russell Simpkins <russellsimpkins(at)hotmail(dot)com>
Cc: mike(at)fuhr(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER records based on parameters in IN clause
Date: 2005-06-29 15:07:18
Message-ID: 1120057638.8208.117.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 2005-06-29 at 09:22, Russell Simpkins wrote:
> fair enough. but a simple order by id would never work.
>

Try this:

select *,
case
when id=2003 then 1
when id=1342 then 2
when id=799 then 3
when id=1450 then 4
end as ob
from
tablename
where
id in (2003,1342,799,1450)
order by
ob;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2005-06-29 21:20:32 Re: ENUM like data type
Previous Message Michael Fuhr 2005-06-29 14:33:30 Re: ORDER records based on parameters in IN clause