Re: SQL question..

From: Petr Bravenec <pbravenec(at)solartec(dot)cz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL question..
Date: 2002-04-18 08:05:52
Message-ID: 3CBE7E60.40003@solartec.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Egon Sommer 2002-04-18 08:27:58 Performance of column order
Previous Message Egon Sommer 2002-04-18 07:57:28 Performance of column order