Re: SQL question.. - Mailing list pgsql-general

From Petr Bravenec
Subject Re: SQL question..
Date
Msg-id 3CBE7E60.40003@solartec.cz
Whole thread Raw
In response to SQL question..  ("Alexis Maldonado" <amaldona@ctcd.cc.tx.us>)
List pgsql-general
It looks like an impossible thing in SQL. The only way to achieve
this may be an temporary table with added sorting information:

create temporary table tpmsort (linenum serial, id int4);
insert into tmpsort (id) values (4);
insert into tmpsort (id) values (3);
insert into tmpsort (id) values (1);
insert into tmpsort (id) values (2); .... in the order you requested

and then

select * from table, tmpsort
   where table.id = tmpsort.id
   order by tmpsort.linenum;

Petr Bravenec

Alexis Maldonado wrote:

>
>
> I have a query list of IDs ( 4,3,1,2,12,5,6,8,7,9,11)
>
>
>
> I want to build a query that gets those IDs in the exact same order
> but when i do
>
>
>
> Select * From Table
>
> Where ID IN ( 4,3,1,2,12,5,6,8,7,9,11)
>
>
>
> It gets all the IDs in random order..
>
>
>
> how can i get them in the order listed?
>



pgsql-general by date:

Previous
From: Lee Kindness
Date:
Subject: determining database size
Next
From: Egon Sommer
Date:
Subject: Performance of column order