With a SELECT...WHERE id IN (...), order results by IN() ?

Posted by Deca on Stack Overflow See other posts from Stack Overflow or by Deca
Published on 2010-03-12T21:23:58Z Indexed on 2010/03/12 21:27 UTC
Read the original article Hit count: 121

Filed under:
|
|

With a query such as:

SELECT * FROM images WHERE id IN (12,9,15,3,1)

is it possible to order the results by the contents of the IN clause?

The result I'm looking for would be something like:

[0] => Array
    (
        [id] => 12
        [file_name] => foo
    )   
[1] => Array
    (
        [id] => 9
        [file_name] => bar
    )   
[2] => Array
    (
        [id] => 15
        [file_name] => baz
    )
...

© Stack Overflow or respective owner

Related posts about mysql

Related posts about in