What's the best way to sort results of a given query by fixed column values ?

Posted by eugene y on Stack Overflow See other posts from Stack Overflow or by eugene y
Published on 2010-03-21T21:45:34Z Indexed on 2010/03/21 21:51 UTC
Read the original article Hit count: 323

Filed under:
|

Example:

SELECT id, name FROM user WHERE id IN (1,2,3,4,5)
ORDER BY FIELD(id, 2, 3, 4, 1, 5)

I've seen some examples using FIND_IN_SET() or FIELD() functions. Which one is better? Are there any more efficient approaches?

Order is supposed to change rarely.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about order