Question: May I know is there any solution to get the result without ordering in Oracle? It is because when I execute the query as follows, it seems to automatically helps me to sort it by ID field.

```
SELECT ID FROM USER WHERE ID IN (5004, 5003, 5005, 5002, 5008);

Actual results          Expected results
---5002                 ---5004
---5003                 ---5003
---5004                 ---5005
---5005                 ---5002
---5008                 ---5008

```

Million thanks if you guys have solutions on this.

Answer: 
This is one way I've seen in the past using `INSTR`:

```
SELECT *
FROM YourTable
WHERE ID IN (5004, 5003, 5005, 5002, 5008)
ORDER BY INSTR ('5004,5003,5005,5002,5008', id)

```

[SQL Fiddle Demo](http://sqlfiddle.com/#!4/0c283/1)

I've also seen use of `CASE` like this:

```
ORDER BY
  CASE ID 
    WHEN 5004 THEN 1   
    WHEN 5003 THEN 2   
    WHEN 5005 THEN 3   
    WHEN 5002 THEN 4   
    WHEN 5008 THEN 5
  END 

```
If your question is about *why the ordering occurs* then the answer is: Do you have an index or primary key defined on the column ID? If yes the database responds to your query with an index scan. That is: it looks up the IDs in the IN clause not in the table itself but in the index defined on your ID-column. Within the index the values are ordered.

To get more information about the execution of your query try Oracle's explain plan feature.

To get the values in a certain order you have to add an ORDER BY clause. One way of doing this would be

```
    select ID 
      from USER 
     where ID in (5004, 5003, 5005, 5002, 5008)
     order by
           case ID
             when 5004 then 1
             when 5003 then 2
             ...
           end;

```

A more general way would be to add an ORDERING column to your table:

```
    select ID 
      from USER 
     where ID in (5004, 5003, 5005, 5002, 5008)
     order by
           ORDERING;

```