| From: | "Prasanth Kumar" <kumar1(at)home(dot)com> |
|---|---|
| To: | <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: Order By Question |
| Date: | 2001-01-24 07:51:50 |
| Message-ID: | 003b01c085da$82aaa4c0$afc8b018@c654771a |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
<snip>
> This seems like the answer must be pretty easy, but I can't think of it:
>
> In the following statement:
>
> select field1 from my_table where field2 in (3, 1, 2);
>
> How can I modify this statement so that the record are returned in the
> order of first those records having field2 = 3, then field2 = 1, then
> field2 = 2.
> As it stands, I am getting them returned in the order of the value of
> field1.
>
<snip>
One way is to have a priority table where each value is mapped to its
associated priority and then you do a join against this table and order by
the priority value instead.
So you might have a table like follows:
priority value
1 3
2 1
3 2
--
Prasanth Kumar
kumar1(at)home(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter T Mount | 2001-01-24 09:08:07 | Re: [SQL] postgresql.largeobject package |
| Previous Message | Michael Davis | 2001-01-24 05:56:10 | RE: plpgsql language |