If the list inside IN is made up of constants and not a subquery, IN() and OR are the same. IN is actually a simplified OR and will execute the same way. For faster execution, create an index for ID and place the most probable value first. The order of the constant on your list does not affect the way the rows are ordered.
If the list is coming form a query, it would be better to use JOIN or EXISTS. In your case, since you need a different sorting, a JOIN might be better. You can include an extra column on the ORDER BY clause even if it's not on your SELECT list.
If it's a list of constant and you still want it ordered that way, you will need to resort to CASE..WHEN..END function. Something like:
- ORDER BY
-
CASE
-
WHEN ID = 5 then 1
-
WHEN ID = 10 then 2
-
WHEN ID = 1 then 3
-
WHEN ID = then 4
-
else 5
-
END
Here's the catch. If that list is dynamic, your ORDER BY should be dynamic as well. Hence you might want to consider using a dynamic sql statement instead.
-- CK