Re: ORDER records based on parameters in IN clause

From: "Russell Simpkins" <russellsimpkins(at)hotmail(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: ORDER records based on parameters in IN clause
Date: 2005-06-29 11:19:22
Message-ID: BAY103-DAV2F286C12D1CD00118F13AB5E00@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>> when I say
>> select * from table where id IN (2003,1342,799, 1450)
>> I would like the records to be ordered as 2003, 1342, 799, 1450.
>Just say:
>select * from table where id IN (2003,1342,799, 1450) ORDER BY id;
>If that doesn't work, you will have to be more specific and send us the
exact query.

Order by id will not do what you want, but this should.
Select * from table where id = 2003;
Union all
Select * from table where id = 1342;
Union all
Select * from table where id = 799;
Union all
Select * from table where id = 1450;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Dawid Kuroczko 2005-06-29 11:44:00 Re: ORDER records based on parameters in IN clause
Previous Message Dawid Kuroczko 2005-06-29 07:09:27 Re: ENUM like data type