Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: simple SQL query question

Re: simple SQL query question

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Wed, 07 Dec 2005 20:08:53 +0100
Message-ID: <nmcep1thvjp4o9ch737j4k714rg94qotiq@4ax.com>


On 7 Dec 2005 10:52:00 -0800, "jimi_xyz_at_hotmail.com" <jimi_xyz_at_hotmail.com> wrote:

>Hi,
>Ok I have this simple query..
>
>SELECT id, name
>FROM people
>where id in (176, 181, 22, 61);
>
>which returns..
>
>id name
>---------------------------------------------------------------------
>22 John
>61 Sam
>176 Tom
>181 Pam
>
>What I want is for the query to return the "names" and "ids" in the
>order of the in() clause.
>Since my in() clause looks like this, in (176, 181, 22, 61). I want my
>results to look like this..
>
>id name
>---------------------------------------------------------------------
>176 Tom
>181 Pam
>22 John
>61 Sam
>
>As you can see they are in the order of the IN() clause, (176, 181, 22,
>61). I am not to sure on how I could do this, one of my friends told me
>to use decode, so i have been messing around with that all day today.
>Any help or ideas will be appreciated.
>
>Thanks,
>-Jimmie

column ranking noprint

SELECT decode(id, 176,1, 181, 2, 22, 61, 3, NULL) ranking, id, name FROM people
where id in (176, 181, 22, 61)
order by decode(id, 176,1, 181, 2, 22, 61, 3, NULL) nulls last;

assuming 8i or higher.

--
Sybrand Bakker, Senior Oracle DBA
Received on Wed Dec 07 2005 - 13:08:53 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US